kvarn_utils::prelude::io

Struct Take

1.0.0 · source
pub struct Take<T> { /* private fields */ }
Expand description

Reader adapter which limits the bytes read from an underlying reader.

This struct is generally created by calling take on a reader. Please see the documentation of take for more details.

Implementations§

source§

impl<T> Take<T>

1.0.0 · source

pub fn limit(&self) -> u64

Returns the number of bytes that can be read before this instance will return EOF.

§Note

This instance may reach EOF after reading fewer bytes than indicated by this method if the underlying Read instance reaches EOF.

§Examples
use std::io;
use std::io::prelude::*;
use std::fs::File;

fn main() -> io::Result<()> {
    let f = File::open("foo.txt")?;

    // read at most five bytes
    let handle = f.take(5);

    println!("limit: {}", handle.limit());
    Ok(())
}