Stdlibfmt
write
import std::fmt::write; · source
FmtWrite
type trait FmtWrite {
write_str(mut &this, source: Str) -> Result<(), FmtError>;
write_char(mut &this, c: char) -> Result<(), FmtError>;
}
The sink trait every formatter writes through. It parallels io::Write but with a different error type and a stricter contract.
write_str is the one required method; write_char has a default that encodes the scalar and routes through it. Its argument is a Str, so a sink only ever sees valid UTF-8 — that invariant is what lets a text container like String be a format target. A byte sink that isn't UTF-8-constrained is an io::Write, not an FmtWrite.
Trait implementations
implement trait FmtWrite for struct Stdout
implement trait FmtWrite for struct Stderr
implement trait FmtWrite for struct String<GlobalAlloc>