pub trait Write {
type Error;
// Required methods
fn write_char(&mut self, val: char) -> Result<(), Self::Error>;
fn size_hint(&mut self, bytes: usize);
// Provided methods
fn write_str(&mut self, val: &str) -> Result<(), Self::Error> { ... }
fn uses_size_hint(&self) -> bool { ... }
fn transform<T: Transform>(self, transformation: T) -> Transformer<T, Self>
where Self: Sized { ... }
}Expand description
Represents types to which characters may be written.
The difference between this trait and byte writers (such as std::io::Write or genio::Write)
is that this guarantees valid UTF-8 encoding - it allows implementing this trait on String.
Required Associated Types§
Required Methods§
Provided Methods§
Sourcefn write_str(&mut self, val: &str) -> Result<(), Self::Error>
fn write_str(&mut self, val: &str) -> Result<(), Self::Error>
Writes whole string.
By default, this just iterates and writes all characters. The implementors are encouraged to override this and provide faster implementation if possible.
If this operation fails the state of underlying writer is unspecified. Re-trying is therefore impossible.
Sourcefn uses_size_hint(&self) -> bool
fn uses_size_hint(&self) -> bool
Tells the user whether the size hint is actually used. This allows the user to skip calculation of the hint.
By default this returns false but size_hint method is still mandatory to prevent people
implementing this trait from forgetting about the size hint.
Sourcefn transform<T: Transform>(self, transformation: T) -> Transformer<T, Self>where
Self: Sized,
fn transform<T: Transform>(self, transformation: T) -> Transformer<T, Self>where
Self: Sized,
Combinator for creating transformed writer.