std::io::Take
implements Read
but not Seek
, this makes Take
less useful when read
an object from it, when the object's size depends on its type (variable length encoded), or when we want to read from Take
as long as there're bytes left.
I.E. This works:
let mut view = file.as_ref().take(100);
let mut buf = Vec::new();
view.read_to_end(&mut buf)?; // read atmost 100B.
But this doesn't work (Take
is not Seek
):
let mut view = file.as_ref().take(100);
while view.stream_position()? < view.stream_len()? {
// read..
}