Add Seek instance for Take

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..
    }
2 Likes
2 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.