[−][src]Struct read_restrict::Restrict
Reader adaptor which restricts the bytes read from an underlying reader,
returning an IO error of the kind ErrorKind::InvalidData
when it is exceeded.
This struct is generally created by calling restrict
on a reader.
Please see the documentation of restrict
for more details.
Implementations
impl<T> Restrict<T>
[src]
pub fn restriction(&self) -> u64
[src]
Returns the number of bytes that can be read before this instance will return an error.
Examples
use std::io; use std::io::prelude::*; use read_restrict::ReadExt; use std::fs::File; fn main() -> io::Result<()> { let f = File::open("foo.txt")?; // read at most five bytes let handle = f.restrict(5); println!("restriction: {}", handle.restriction()); Ok(()) }
pub fn set_restriction(&mut self, restriction: u64)
[src]
Sets the number of bytes that can be read before this instance will
return an error. This is the same as constructing a new Restrict
instance, so
the amount of bytes read and the previous restriction value don't matter when
calling this method.
Examples
use std::io; use std::io::prelude::*; use std::fs::File; use read_restrict::ReadExt; fn main() -> io::Result<()> { let f = File::open("foo.txt")?; // read at most five bytes let mut handle = f.restrict(5); handle.set_restriction(10); assert_eq!(handle.restriction(), 10); Ok(()) }
pub fn into_inner(self) -> T
[src]
Consumes the Restrict
, returning the wrapped reader.
Examples
use std::io; use std::io::prelude::*; use std::fs::File; use read_restrict::ReadExt; fn main() -> io::Result<()> { let mut file = File::open("foo.txt")?; let mut buffer = [0; 5]; let mut handle = file.restrict(5); handle.read(&mut buffer)?; let file = handle.into_inner(); Ok(()) }
pub fn get_ref(&self) -> &T
[src]
Gets a reference to the underlying reader.
Examples
use std::io; use std::io::prelude::*; use std::fs::File; use read_restrict::ReadExt; fn main() -> io::Result<()> { let mut file = File::open("foo.txt")?; let mut buffer = [0; 5]; let mut handle = file.restrict(5); handle.read(&mut buffer)?; let file = handle.get_ref(); Ok(()) }
pub fn get_mut(&mut self) -> &mut T
[src]
Gets 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
Restrict
.
Examples
use std::io; use std::io::prelude::*; use std::fs::File; use read_restrict::ReadExt; fn main() -> io::Result<()> { let mut file = File::open("foo.txt")?; let mut buffer = [0; 5]; let mut handle = file.restrict(5); handle.read(&mut buffer)?; let file = handle.get_mut(); Ok(()) }
Trait Implementations
impl<T: BufRead> BufRead for Restrict<T>
[src]
pub fn fill_buf(&mut self) -> Result<&[u8]>
[src]
pub fn consume(&mut self, amt: usize)
[src]
pub fn read_until(
&mut self,
byte: u8,
buf: &mut Vec<u8, Global>
) -> Result<usize, Error>
1.0.0[src]
&mut self,
byte: u8,
buf: &mut Vec<u8, Global>
) -> Result<usize, Error>
pub fn read_line(&mut self, buf: &mut String) -> Result<usize, Error>
1.0.0[src]
pub fn split(self, byte: u8) -> Split<Self>
1.0.0[src]
pub fn lines(self) -> Lines<Self>
1.0.0[src]
impl<T: Debug> Debug for Restrict<T>
[src]
impl<T: Read> Read for Restrict<T>
[src]
pub fn read(&mut self, buf: &mut [u8]) -> Result<usize>
[src]
pub fn read_vectored(
&mut self,
bufs: &mut [IoSliceMut<'_>]
) -> Result<usize, Error>
1.36.0[src]
&mut self,
bufs: &mut [IoSliceMut<'_>]
) -> Result<usize, Error>
pub fn is_read_vectored(&self) -> bool
[src]
pub unsafe fn initializer(&self) -> Initializer
[src]
pub fn read_to_end(&mut self, buf: &mut Vec<u8, Global>) -> Result<usize, Error>
1.0.0[src]
pub fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
1.0.0[src]
pub fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
1.6.0[src]
pub fn by_ref(&mut self) -> &mut Self
1.0.0[src]
pub fn bytes(self) -> Bytes<Self>
1.0.0[src]
pub fn chain<R>(self, next: R) -> Chain<Self, R> where
R: Read,
1.0.0[src]
R: Read,
pub fn take(self, limit: u64) -> Take<Self>
1.0.0[src]
Auto Trait Implementations
impl<T> RefUnwindSafe for Restrict<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
impl<T> Send for Restrict<T> where
T: Send,
T: Send,
impl<T> Sync for Restrict<T> where
T: Sync,
T: Sync,
impl<T> Unpin for Restrict<T> where
T: Unpin,
T: Unpin,
impl<T> UnwindSafe for Restrict<T> where
T: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<R> ReadExt for R where
R: Read,
[src]
R: Read,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,