Skip to main content

Write

Trait Write 

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

    // Provided methods
    fn write_all(&mut self, buf: &[u8]) -> Result<()> { ... }
    fn write_fmt(&mut self, args: Arguments<'_>) -> Result<()> { ... }
    fn by_ref(&mut self) -> &mut Self
       where Self: Sized { ... }
}
Expand description

A trait for objects which are byte-oriented sinks.

See std::io::Write for more details.

Required Methods§

Source

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

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

Source

fn flush(&mut self) -> Result<()>

Flush this output stream, ensuring that all intermediately buffered contents reach their destination.

Provided Methods§

Source

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

Attempts to write an entire buffer into this writer.

Source

fn write_fmt(&mut self, args: Arguments<'_>) -> Result<()>

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

Source

fn by_ref(&mut self) -> &mut Self
where Self: Sized,

Creates a “by reference” adapter for this instance of Write.

The returned adapter also implements Write and will simply borrow this current writer.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl Write for &mut [u8]

Source§

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

Source§

fn flush(&mut self) -> Result<()>

Source§

fn write_all(&mut self, data: &[u8]) -> Result<()>

Source§

impl Write for BorrowedCursor<'_, u8>

Source§

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

Source§

fn flush(&mut self) -> Result<()>

Source§

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

Source§

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

Source§

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

Source§

fn flush(&mut self) -> Result<()>

Source§

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

Source§

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

Implementors§

Source§

impl Write for &Empty

Source§

impl Write for &Sink

Source§

impl Write for Cursor<&mut [u8]>

Source§

impl Write for Empty

Source§

impl Write for Sink

Source§

impl<W: ?Sized + Write> Write for BufWriter<W>

Source§

impl<W: ?Sized + Write> Write for LineWriter<W>

Source§

impl<W> Write for WriteFn<W>
where W: FnMut(&[u8]) -> Result<usize>,

Source§

impl<const N: usize> Write for Cursor<[u8; N]>