pub trait WriteAtomic: Write {
// Required methods
fn is_ready_to_write(&self) -> bool;
fn write_or_buf(&mut self, buf: &[u8]) -> Result<()>;
// Provided method
fn write_atomic(&mut self, buf: &[u8]) -> Result<()> { ... }
}Expand description
The trait guarantees that the data are either written in full or, in case of an error, none of the data is written. Types implementing the trait must also guarantee that multiple attempts to write do not result in data to be written out of the initial ordering.
Required Methods§
Sourcefn is_ready_to_write(&self) -> bool
fn is_ready_to_write(&self) -> bool
Checks whether resource can be written to without blocking.
Sourcefn write_or_buf(&mut self, buf: &[u8]) -> Result<()>
fn write_or_buf(&mut self, buf: &[u8]) -> Result<()>
Writes to the resource in a non-blocking way, buffering the data if necessary, or failing with a system-level error.
This method shouldn’t be called directly; call WriteAtomic::write_atomic instead.
The method must handle std::io::Error of kind
ErrorKind::Interrupted, ErrorKind::WouldBlock, ErrorKind::WriteZero.
and buffer the data in such cases.
Provided Methods§
Sourcefn write_atomic(&mut self, buf: &[u8]) -> Result<()>
fn write_atomic(&mut self, buf: &[u8]) -> Result<()>
Atomic non-blocking I/O write operation, which must either write the whole buffer to a resource without blocking or fail.
§Panics
If WriteAtomic::write_or_buf returns an std::io::Error of kind
ErrorKind::Interrupted, ErrorKind::WouldBlock, ErrorKind::WriteZero.
In this case, WriteAtomic::write_or_buf is expected to buffer.