Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "rev_buf_reader"
version = "0.3.0"
authors = ["André Vicente Milack <andrevicente.m@gmail.com>"]
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/*"]
Expand All @@ -14,4 +14,4 @@ default = []
read_initializer = []

[dependencies]
memchr = "2.4.1"
memchr = "2.8.0"
32 changes: 17 additions & 15 deletions src/io_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,23 @@ pub(crate) unsafe fn append_to_string<F>(buf: &mut String, f: F) -> io::Result<u
where
F: FnOnce(&mut Vec<u8>) -> io::Result<usize>,
{
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
}
}
}

Expand Down
Loading