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§
Sourcefn write(&mut self, buf: &str) -> Result<usize>
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.
Provided Methods§
Sourcefn write_all(&mut self, buf: &str) -> Result<()>
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.
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.