Trait fast_fmt::Write [] [src]

pub trait Write {
    type Error;
    fn write_char(&mut self, val: char) -> Result<(), Self::Error>;
    fn size_hint(&mut self, bytes: usize);

    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
, { ... } }

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.

Associated Types

Type of error returned if write fails.

Required Methods

Writes single char.

If this operation fails the state of underlying writer is unspecified. Re-trying is therefore impossible.

Hints that implementor should allocate enough space so that string containing bytes UTF-8 bytes can be stored in it.

Warning: the number of bytes (chars) actually written might differ from this number! The writer must NOT fail if it does!

Provided Methods

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.

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.

Combinator for creating transformed writer.

Implementors