Struct timeout_readwrite::reader::TimeoutReader
source · [−]Expand description
The TimeoutReader
struct adds read timeouts to any reader.
The read
call on a Read
instance will block forever until data is available.
A TimeoutReader
will wait until data is available, up until an optional timeout,
before actually performing the read
operation.
If any Read
operation times out, the method called will return
an io::ErrorKind::TimedOut
variant as the value of io::Error
. All other
error values that would normally be produced by the underlying implementation
of the Read
trait could also be produced by the TimeoutReader
.
Implementations
sourceimpl<H> TimeoutReader<H> where
H: Read + AsRawFd,
impl<H> TimeoutReader<H> where
H: Read + AsRawFd,
sourcepub fn new<T: Into<Option<Duration>>>(handle: H, timeout: T) -> TimeoutReader<H>ⓘNotable traits for TimeoutReader<H>impl<H> Read for TimeoutReader<H> where
H: Read + AsRawFd,
pub fn new<T: Into<Option<Duration>>>(handle: H, timeout: T) -> TimeoutReader<H>ⓘNotable traits for TimeoutReader<H>impl<H> Read for TimeoutReader<H> where
H: Read + AsRawFd,
H: Read + AsRawFd,
Create a new TimeoutReader
with an optional timeout.
Examples
This first example creates the TimeoutReader
with a 5-second timeout.
use timeout_readwrite::TimeoutReader;
use std::fs::File;
use std::time::Duration;
let mut f = File::open("file.txt")?;
let mut rdr = TimeoutReader::new(f, Duration::new(5, 0));
This example creates the TimeoutReader
without a timeout at all.
use timeout_readwrite::TimeoutReader;
use std::fs::File;
use std::time::Duration;
let mut f = File::open("file.txt")?;
let mut rdr = TimeoutReader::new(f, None);
Trait Implementations
sourceimpl<H> AsRawFd for TimeoutReader<H> where
H: Read + AsRawFd,
impl<H> AsRawFd for TimeoutReader<H> where
H: Read + AsRawFd,
sourceimpl<H> Clone for TimeoutReader<H> where
H: Read + AsRawFd + Clone,
impl<H> Clone for TimeoutReader<H> where
H: Read + AsRawFd + Clone,
sourcefn clone(&self) -> TimeoutReader<H>ⓘNotable traits for TimeoutReader<H>impl<H> Read for TimeoutReader<H> where
H: Read + AsRawFd,
fn clone(&self) -> TimeoutReader<H>ⓘNotable traits for TimeoutReader<H>impl<H> Read for TimeoutReader<H> where
H: Read + AsRawFd,
H: Read + AsRawFd,
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl<H> Read for TimeoutReader<H> where
H: Read + AsRawFd,
impl<H> Read for TimeoutReader<H> where
H: Read + AsRawFd,
sourcefn read(&mut self, buf: &mut [u8]) -> Result<usize>
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
Pull some bytes from this source into the specified buffer, returning how many bytes were read. Read more
1.36.0 · sourcefn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
Like read
, except that it reads into a slice of buffers. Read more
sourcefn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
can_vector
)Determines if this Read
er has an efficient read_vectored
implementation. Read more
1.0.0 · sourcefn read_to_end(&mut self, buf: &mut Vec<u8, Global>) -> Result<usize, Error>
fn read_to_end(&mut self, buf: &mut Vec<u8, Global>) -> Result<usize, Error>
Read all bytes until EOF in this source, placing them into buf
. Read more
1.0.0 · sourcefn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
Read all bytes until EOF in this source, appending them to buf
. Read more
1.6.0 · sourcefn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
Read the exact number of bytes required to fill buf
. Read more
sourcefn read_buf(&mut self, buf: &mut ReadBuf<'_>) -> Result<(), Error>
fn read_buf(&mut self, buf: &mut ReadBuf<'_>) -> Result<(), Error>
read_buf
)Pull some bytes from this source into the specified buffer. Read more
sourcefn read_buf_exact(&mut self, buf: &mut ReadBuf<'_>) -> Result<(), Error>
fn read_buf_exact(&mut self, buf: &mut ReadBuf<'_>) -> Result<(), Error>
read_buf
)Read the exact number of bytes required to fill buf
. Read more
1.0.0 · sourcefn by_ref(&mut self) -> &mut Self
fn by_ref(&mut self) -> &mut Self
Creates a “by reference” adaptor for this instance of Read
. Read more
sourceimpl<H> Seek for TimeoutReader<H> where
H: Read + AsRawFd + Seek,
impl<H> Seek for TimeoutReader<H> where
H: Read + AsRawFd + Seek,
sourcefn seek(&mut self, pos: SeekFrom) -> Result<u64>
fn seek(&mut self, pos: SeekFrom) -> Result<u64>
Seek to an offset, in bytes, in a stream. Read more
1.55.0 · sourcefn rewind(&mut self) -> Result<(), Error>
fn rewind(&mut self) -> Result<(), Error>
Rewind to the beginning of a stream. Read more
Auto Trait Implementations
impl<H> RefUnwindSafe for TimeoutReader<H> where
H: RefUnwindSafe,
impl<H> Send for TimeoutReader<H> where
H: Send,
impl<H> Sync for TimeoutReader<H> where
H: Sync,
impl<H> Unpin for TimeoutReader<H> where
H: Unpin,
impl<H> UnwindSafe for TimeoutReader<H> where
H: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<H> TimeoutReadExt<H> for H where
H: Read + AsRawFd,
impl<H> TimeoutReadExt<H> for H where
H: Read + AsRawFd,
fn with_timeout<T>(self, timeout: T) -> TimeoutReader<H>ⓘNotable traits for TimeoutReader<H>impl<H> Read for TimeoutReader<H> where
H: Read + AsRawFd,
where
T: Into<Option<Duration>>,
H: Read + AsRawFd,