Trait StrWrite

Source
pub trait StrWrite {
    // Required methods
    fn write(&mut self, buf: &str) -> Result<usize>;
    fn flush(&mut self) -> Result<()>;
    fn write_fmt(&mut self, args: Arguments<'_>) -> Result<()>;

    // Provided methods
    fn write_all(&mut self, buf: &str) -> Result<()> { ... }
    fn by_ref(&mut self) -> &mut Self { ... }
}
Expand description

This trait is designed to provide a similar interface to io::Write, but is designed to operate on strings. Unlike fmt::Write, it can report partial writes, but it guarantees that a whole number of code points were written with every write. Generally this involves buffering partial code points as necessary.

Required Methods§

Source

fn write(&mut self, buf: &str) -> Result<usize>

Write a str to the writer. Like io::Write::write, this function returns the number of bytes written; it additionally guarantees that the number of written bytes encompasses a whole number of code points. Like with io::Write, it also guarantees that errors mean that 0 bytes were written, and that the write can therefore (potentially) be retried.

Source

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

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

Source

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

Write some format arguments to the stream. This makes StrWrite compatible with write!, println!, etc.

Provided Methods§

Source

fn write_all(&mut self, buf: &str) -> Result<()>

Continuously write buf to the stream until either the whole thing is written or an error occurs. An implementation of this function is provided by default, which calls write in a loop, but in general implementors should wrap the underlying write_all method, if available.

Source

fn by_ref(&mut self) -> &mut Self

Get a mutable reference to this writer

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<'a, T: Write> StrWrite for T

Source§

impl<W: Write> StrWrite for StrWriter<W>