pub struct TimeoutWriter<H>{ /* private fields */ }
Expand description
The TimeoutWriter
struct adds write timeouts to any writer.
The write
call on a Write
instance can block forever until data cannot be written.
A TimeoutWriter
will wait until data can be written, up until an optional timeout,
before actually performing the write
operation on the underlying writer.
If any Write
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 Write
trait could also be produced by the TimeoutWriter
.
Implementations§
Source§impl<H> TimeoutWriter<H>
impl<H> TimeoutWriter<H>
Sourcepub fn new<T: Into<Option<Duration>>>(handle: H, timeout: T) -> TimeoutWriter<H> ⓘ
pub fn new<T: Into<Option<Duration>>>(handle: H, timeout: T) -> TimeoutWriter<H> ⓘ
Create a new TimeoutWriter
with an optional timeout.
§Examples
This first example creates the TimeoutWriter
with a 5-second timeout.
use timeout_readwrite::TimeoutWriter;
use std::fs::File;
use std::time::Duration;
let mut f = File::open("file.txt")?;
let mut wtr = TimeoutWriter::new(f, Duration::new(5, 0));
This example creates the TimeoutWriter
without a timeout at all.
use timeout_readwrite::TimeoutWriter;
use std::fs::File;
use std::time::Duration;
let mut f = File::open("file.txt")?;
let mut wtr = TimeoutWriter::new(f, None);
Trait Implementations§
Source§impl<H> AsFd for TimeoutWriter<H>
impl<H> AsFd for TimeoutWriter<H>
Source§fn as_fd(&self) -> BorrowedFd<'_>
fn as_fd(&self) -> BorrowedFd<'_>
Source§impl<H> Clone for TimeoutWriter<H>
impl<H> Clone for TimeoutWriter<H>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl<H> Seek for TimeoutWriter<H>
impl<H> Seek for TimeoutWriter<H>
Source§fn seek(&mut self, pos: SeekFrom) -> Result<u64>
fn seek(&mut self, pos: SeekFrom) -> Result<u64>
1.55.0 · Source§fn rewind(&mut self) -> Result<(), Error>
fn rewind(&mut self) -> Result<(), Error>
Source§fn stream_len(&mut self) -> Result<u64, Error>
fn stream_len(&mut self) -> Result<u64, Error>
seek_stream_len
)Source§impl<H> Write for TimeoutWriter<H>
impl<H> Write for TimeoutWriter<H>
Source§fn write(&mut self, buf: &[u8]) -> Result<usize>
fn write(&mut self, buf: &[u8]) -> Result<usize>
Source§fn flush(&mut self) -> Result<()>
fn flush(&mut self) -> Result<()>
Source§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
can_vector
)1.0.0 · Source§fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
Source§fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
write_all_vectored
)