Skip to content

Commit

Permalink
Function encode_buffer_ascii is infallible
Browse files Browse the repository at this point in the history
  • Loading branch information
qsantos committed Jun 19, 2024
1 parent c4de554 commit 3185ae7
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/encode_ascii.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::io::{Read, Write};

use crate::encode_ascii_mapping::ASCII_TO_QWORD;

fn encode_buffer_ascii(input: &[u8], output_buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
fn encode_buffer_ascii(input: &[u8], output_buf: &mut Vec<u8>) {
let mut cur = output_buf.len();
output_buf.reserve(input.len() * 18 + cur);
for c in input {
Expand Down Expand Up @@ -34,7 +34,6 @@ fn encode_buffer_ascii(input: &[u8], output_buf: &mut Vec<u8>) -> Result<(), std
// SAFETY: the first `cur` bytes of `output_buf` are initialized because we only increase cur
// after writing to `output_buf`
unsafe { output_buf.set_len(cur) };
Ok(())
}

/// Encode ASCII characters from a [byte slice][slice] into a [String].
Expand All @@ -57,7 +56,7 @@ fn encode_buffer_ascii(input: &[u8], output_buf: &mut Vec<u8>) -> Result<(), std
/// ```
pub fn encode_string_ascii(input: &[u8]) -> String {
let mut output_buf = Vec::new();
encode_buffer_ascii(input, &mut output_buf).unwrap();
encode_buffer_ascii(input, &mut output_buf);
if output_buf.last() == Some(&b' ') {
output_buf.pop();
}
Expand Down Expand Up @@ -96,7 +95,7 @@ pub fn encode_stream_ascii(input: &mut impl Read, output: &mut impl Write) {
if bytes_read == 0 {
break;
}
encode_buffer_ascii(&input_buf[..bytes_read], &mut output_buf).unwrap();
encode_buffer_ascii(&input_buf[..bytes_read], &mut output_buf);
if output_buf.is_empty() {
} else if output_buf.last() == Some(&b' ') {
output_buf.pop();
Expand Down

0 comments on commit 3185ae7

Please sign in to comment.