Trait reactor::WriteAtomic

source ·
pub trait WriteAtomic: Write {
    // Required methods
    fn is_ready_to_write(&self) -> bool;
    fn empty_write_buf(&mut self) -> Result<bool>;
    fn write_or_buf(&mut self, buf: &[u8]) -> Result<()>;

    // Provided method
    fn write_atomic(&mut self, buf: &[u8]) -> Result<(), WriteError> { ... }
}
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 do the write would not result in data to be written out of the initial ordering.

Required Methods§

source

fn is_ready_to_write(&self) -> bool

Checks whether resource can be written to without blocking.

source

fn empty_write_buf(&mut self) -> Result<bool>

Empties any write buffers in a non-blocking way. If a non-blocking operation is not possible, errors with io::ErrorKind::WouldBlock kind of io::Error.

Returns

If the buffer contained any data before this operation.

source

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; Self::write_atomic must be used instead.

Provided Methods§

source

fn write_atomic(&mut self, buf: &[u8]) -> Result<(), WriteError>

Atomic non-blocking I/O write operation, which must either write the whole buffer to a resource without blocking - or fail with WriteError::NotReady error.

Implementors§