1.0.0[−][src]Trait frame_support::dispatch::fmt::Write
A collection of methods that are required to format a message into a stream.
This trait is the type which this modules requires when formatting
information. This is similar to the standard library's io::Write
trait,
but it is only intended for use in libcore.
This trait should generally not be implemented by consumers of the standard
library. The write!
macro accepts an instance of io::Write
, and the
io::Write
trait is favored over implementing this trait.
Required methods
fn write_str(&mut self, s: &str) -> Result<(), Error>
Writes 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 Error
on error.
Examples
use std::fmt::{Error, Write}; fn writer<W: Write>(f: &mut W, s: &str) -> Result<(), Error> { f.write_str(s) } let mut buf = String::new(); writer(&mut buf, "hola").unwrap(); assert_eq!(&buf, "hola");
Provided methods
fn write_char(&mut self, c: char) -> Result<(), Error>
1.1.0
Writes a char
into this writer, returning whether the write succeeded.
A single char
may 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 Error
on error.
Examples
use std::fmt::{Error, Write}; fn writer<W: Write>(f: &mut W, c: char) -> Result<(), Error> { f.write_char(c) } let mut buf = String::new(); writer(&mut buf, 'a').unwrap(); writer(&mut buf, 'b').unwrap(); assert_eq!(&buf, "ab");
fn write_fmt(&mut self, args: Arguments<'_>) -> Result<(), Error>
Glue 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.
Examples
use std::fmt::{Error, Write}; fn writer<W: Write>(f: &mut W, s: &str) -> Result<(), Error> { f.write_fmt(format_args!("{}", s)) } let mut buf = String::new(); writer(&mut buf, "world").unwrap(); assert_eq!(&buf, "world");
Implementations on Foreign Types
impl<'_, W> Write for &'_ mut W where
W: Write + ?Sized,
[src]
W: Write + ?Sized,
fn write_str(&mut self, s: &str) -> Result<(), Error>
[src]
fn write_char(&mut self, c: char) -> Result<(), Error>
[src]
fn write_fmt(&mut self, args: Arguments<'_>) -> Result<(), Error>
[src]
impl Write for String
[src]
fn write_str(&mut self, s: &str) -> Result<(), Error>
[src]
fn write_char(&mut self, c: char) -> Result<(), Error>
[src]
impl<A> Write for ArrayString<A> where
A: Array<Item = u8> + Copy,
[src]
A: Array<Item = u8> + Copy,
Write
appends written data to the end of the string.
fn write_char(&mut self, c: char) -> Result<(), Error>
[src]
fn write_str(&mut self, s: &str) -> Result<(), Error>
[src]
impl<A> Write for ArrayString<A> where
A: Array<Item = u8>,
[src]
A: Array<Item = u8>,
Write
appends written data to the end of the string.