diff --git a/Cargo.toml b/Cargo.toml index 7298475..9ed94c0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ name = "rev_buf_reader" version = "0.3.0" authors = ["André Vicente Milack "] -edition = "2021" +edition = "2024" description = "Crate that provides a buffered reader capable of reading chunks of bytes of a data stream in reverse order. Its implementation is an adapted copy of BufReader from the nightly std::io." repository = "https://github.com/andre-vm/rev_buf_reader" exclude = ["base/*"] @@ -14,4 +14,4 @@ default = [] read_initializer = [] [dependencies] -memchr = "2.4.1" +memchr = "2.8.0" diff --git a/src/io_helpers.rs b/src/io_helpers.rs index 169dde9..0c793f3 100644 --- a/src/io_helpers.rs +++ b/src/io_helpers.rs @@ -40,21 +40,23 @@ pub(crate) unsafe fn append_to_string(buf: &mut String, f: F) -> io::Result) -> io::Result, { - let mut g = Guard { - len: buf.len(), - buf: buf.as_mut_vec(), - }; - let ret = f(g.buf); - if str::from_utf8(&g.buf[g.len..]).is_err() { - ret.and_then(|_| { - Err(io::Error::new( - io::ErrorKind::InvalidData, - "stream did not contain valid UTF-8", - )) - }) - } else { - g.len = g.buf.len(); - ret + unsafe { + let mut g = Guard { + len: buf.len(), + buf: buf.as_mut_vec(), + }; + let ret = f(g.buf); + if str::from_utf8(&g.buf[g.len..]).is_err() { + ret.and_then(|_| { + Err(io::Error::new( + io::ErrorKind::InvalidData, + "stream did not contain valid UTF-8", + )) + }) + } else { + g.len = g.buf.len(); + ret + } } }