pub trait TryWrite {
// Required method
fn try_write_str(&mut self, s: &str) -> Result<(), Error>;
// Provided method
fn try_write_char(&mut self, c: char) -> Result<(), Error> { ... }
}
Expand description
Fallible write formatting implementation.
Required Methods§
Sourcefn try_write_str(&mut self, s: &str) -> Result<(), Error>
fn try_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 rune::alloc::fmt::TryWrite;
use rune::alloc::{String, Error};
fn writer<W: TryWrite>(f: &mut W, s: &str) -> Result<(), Error> {
f.try_write_str(s)
}
let mut buf = String::new();
writer(&mut buf, "hola")?;
assert_eq!(&buf, "hola");
Provided Methods§
Sourcefn try_write_char(&mut self, c: char) -> Result<(), Error>
fn try_write_char(&mut self, c: char) -> Result<(), Error>
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 rune::alloc::fmt::TryWrite;
use rune::alloc::{String, Error};
fn writer<W: TryWrite>(f: &mut W, c: char) -> Result<(), Error> {
f.try_write_char(c)
}
let mut buf = String::new();
writer(&mut buf, 'a')?;
writer(&mut buf, 'b')?;
assert_eq!(&buf, "ab");