Struct Take
struct Take<T> { ... }
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
impl<T> Take<T>
fn limit(self: &Self) -> u64Returns the number of bytes that can be read before this instance will return EOF.
Note
This instance may reach
EOFafter reading fewer bytes than indicated by this method if the underlyingReadinstance 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(()) }fn position(self: &Self) -> u64Returns the number of bytes read so far.
fn set_limit(self: &mut Self, limit: u64)Sets the number of bytes that can be read before this instance will return EOF. This is the same as constructing a new
Takeinstance, so the amount of bytes read and the previous limit value don't matter when calling this method.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 mut handle = f.take(5); handle.set_limit(10); assert_eq!(handle.limit(), 10); Ok(()) }fn into_inner(self: Self) -> TConsumes the
Take, returning the wrapped reader.Examples
use std::io; use std::io::prelude::*; use std::fs::File; fn main() -> io::Result<()> { let mut file = File::open("foo.txt")?; let mut buffer = [0; 5]; let mut handle = file.take(5); handle.read(&mut buffer)?; let file = handle.into_inner(); Ok(()) }fn get_ref(self: &Self) -> &TGets a reference to the underlying reader.
Care should be taken to avoid modifying the internal I/O state of the underlying reader as doing so may corrupt the internal limit of this
Take.Examples
use std::io; use std::io::prelude::*; use std::fs::File; fn main() -> io::Result<()> { let mut file = File::open("foo.txt")?; let mut buffer = [0; 5]; let mut handle = file.take(5); handle.read(&mut buffer)?; let file = handle.get_ref(); Ok(()) }fn get_mut(self: &mut Self) -> &mut TGets a mutable reference to the underlying reader.
Care should be taken to avoid modifying the internal I/O state of the underlying reader as doing so may corrupt the internal limit of this
Take.Examples
use std::io; use std::io::prelude::*; use std::fs::File; fn main() -> io::Result<()> { let mut file = File::open("foo.txt")?; let mut buffer = [0; 5]; let mut handle = file.take(5); handle.read(&mut buffer)?; let file = handle.get_mut(); Ok(()) }
impl<T> Any for Take<T>
fn type_id(self: &Self) -> TypeId
impl<T> Borrow for Take<T>
fn borrow(self: &Self) -> &T
impl<T> BorrowMut for Take<T>
fn borrow_mut(self: &mut Self) -> &mut T
impl<T> Freeze for Take<T>
impl<T> From for Take<T>
fn from(t: T) -> TReturns the argument unchanged.
impl<T> RefUnwindSafe for Take<T>
impl<T> Send for Take<T>
impl<T> Sync for Take<T>
impl<T> Unpin for Take<T>
impl<T> UnwindSafe for Take<T>
impl<T, U> Into for Take<T>
fn into(self: Self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom for Take<T>
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto for Take<T>
fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>
impl<T: $crate::fmt::Debug> Debug for Take<T>
fn fmt(self: &Self, f: &mut $crate::fmt::Formatter<'_>) -> $crate::fmt::Result
impl<T: BufRead> BufRead for Take<T>
fn fill_buf(self: &mut Self) -> Result<&[u8]>fn consume(self: &mut Self, amt: usize)
impl<T: Read> Read for Take<T>
fn read(self: &mut Self, buf: &mut [u8]) -> Result<usize>fn read_buf(self: &mut Self, buf: BorrowedCursor<'_>) -> Result<()>
impl<T: Seek> Seek for Take<T>
fn seek(self: &mut Self, pos: SeekFrom) -> Result<u64>fn stream_len(self: &mut Self) -> Result<u64>fn stream_position(self: &mut Self) -> Result<u64>fn seek_relative(self: &mut Self, offset: i64) -> Result<()>