Trait Write
trait Write
A trait for writing or formatting into Unicode-accepting buffers or streams.
This trait only accepts UTF-8–encoded data and is not flushable. If you only
want to accept Unicode and you don't need flushing, you should implement this trait;
otherwise you should implement std::io::Write.
Required Methods
fn write_str(self: &mut Self, s: &str) -> ResultWrites a string slice into this writer, returning whether the write succeeded.
This method can only succeed if the entire string slice was successfully written, and this method will not return until all data has been written or an error occurs.
Errors
This function will return an instance of [
std::fmt::Error][Error] on error.The purpose of that error is to abort the formatting operation when the underlying destination encounters some error preventing it from accepting more text; in particular, it does not communicate any information about what error occurred. It should generally be propagated rather than handled, at least when implementing formatting traits.
Examples
use ; let mut buf = Stringnew; writer?; assert_eq!; # Ok
Provided Methods
fn write_char(self: &mut Self, c: char) -> ResultWrites a
charinto this writer, returning whether the write succeeded.A single
charmay be encoded as more than one byte. This method can only succeed if the entire byte sequence was successfully written, and this method will not return until all data has been written or an error occurs.Errors
This function will return an instance of
Erroron error.Examples
use ; let mut buf = Stringnew; writer?; writer?; assert_eq!; # Okfn write_fmt(self: &mut Self, args: Arguments<'_>) -> ResultGlue for usage of the [
write!] macro with implementors of this trait.This method should generally not be invoked manually, but rather through the [
write!] macro itself.Errors
This function will return an instance of
Erroron error. Please see write_str for details.Examples
use ; let mut buf = Stringnew; writer?; assert_eq!; # Ok
Implementors
impl<W: Write + ?Sized> Write for &mut Wimpl Write for Formatter<'_>