Trait embedded_io::Write

source ·
pub trait Write: ErrorType {
    // Required methods
    fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error>;
    fn flush(&mut self) -> Result<(), Self::Error>;

    // Provided methods
    fn write_all(
        &mut self,
        buf: &[u8]
    ) -> Result<(), WriteAllError<Self::Error>> { ... }
    fn write_fmt(
        &mut self,
        fmt: Arguments<'_>
    ) -> Result<(), WriteFmtError<Self::Error>> { ... }
}
Expand description

Blocking writer.

This trait is the embedded-io equivalent of std::io::Write.

Required Methods§

source

fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error>

Write a buffer into this writer, returning how many bytes were written.

If the writer is not currently ready to accept more bytes (for example, its buffer is full), this function blocks until it is ready to accept least one byte.

If it’s ready to accept bytes, a non-zero amount of bytes is written from the beginning of buf, and the amount is returned. It is not guaranteed that all available buffer space is filled, i.e. it is possible for the implementation to write an amount of bytes less than buf.len() while the writer continues to be ready to accept more bytes immediately.

Implementations should never return Ok(0) when buf.len() != 0. Situations where the writer is not able to accept more bytes and likely never will are better indicated with errors.

If buf.len() == 0, write returns without blocking, with either Ok(0) or an error. The Ok(0) doesn’t indicate an error.

source

fn flush(&mut self) -> Result<(), Self::Error>

Flush this output stream, blocking until all intermediately buffered contents reach their destination.

Provided Methods§

source

fn write_all(&mut self, buf: &[u8]) -> Result<(), WriteAllError<Self::Error>>

Write an entire buffer into this writer.

This function calls write() in a loop until exactly buf.len() bytes have been written, blocking if needed.

If you are using WriteReady to avoid blocking, you should not use this function. WriteReady::write_ready() returning true only guarantees the first call to write() will not block, so this function may still block in subsequent calls.

source

fn write_fmt( &mut self, fmt: Arguments<'_> ) -> Result<(), WriteFmtError<Self::Error>>

Write a formatted string into this writer, returning any error encountered.

This function calls write() in a loop until the entire formatted string has been written, blocking if needed.

If you are using WriteReady to avoid blocking, you should not use this function. WriteReady::write_ready() returning true only guarantees the first call to write() will not block, so this function may still block in subsequent calls.

Implementations on Foreign Types§

source§

impl<T: ?Sized + Write> Write for Box<T>

Available on crate features std or alloc only.
source§

fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error>

source§

fn flush(&mut self) -> Result<(), Self::Error>

source§

impl Write for Vec<u8>

Available on crate features std or alloc only.
source§

fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error>

source§

fn flush(&mut self) -> Result<(), Self::Error>

source§

impl Write for &mut [u8]

Write is implemented for &mut [u8] by copying into the slice, overwriting its data.

Note that writing updates the slice to point to the yet unwritten part. The slice will be empty when it has been completely overwritten.

If the number of bytes to be written exceeds the size of the slice, write operations will return short writes: ultimately, Ok(0); in this situation, write_all returns an error of kind ErrorKind::WriteZero.

source§

fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error>

source§

fn flush(&mut self) -> Result<(), Self::Error>

source§

impl<T: ?Sized + Write> Write for &mut T

source§

fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error>

source§

fn flush(&mut self) -> Result<(), Self::Error>

Implementors§