Skip to main content

TextWrite

Trait TextWrite 

Source
pub trait TextWrite {
    type Error;

    // Required methods
    fn write_char(&mut self, ch: char) -> Result<(), Self::Error>;
    fn write_chars(&mut self, chars: &[char]) -> Result<(), Self::Error>;
    fn write_str(&mut self, text: &str) -> Result<(), Self::Error>;
    fn write_line(&mut self, line: &str) -> Result<(), Self::Error>;
    fn flush(&mut self) -> Result<(), Self::Error>;

    // Provided method
    fn line_ending(&self) -> LineEnding { ... }
}
Expand description

Writes Unicode text to a text sink.

TextWrite accepts Rust Unicode text and delegates byte encoding, storage, logging, or other sink-specific behavior to the concrete implementation.

Required Associated Types§

Source

type Error

Error returned by this text sink.

Required Methods§

Source

fn write_char(&mut self, ch: char) -> Result<(), Self::Error>

Writes one Unicode scalar value.

§Parameters
  • ch: Character to write.
§Errors

Returns an implementation-specific error when the character cannot be accepted by the sink.

Source

fn write_chars(&mut self, chars: &[char]) -> Result<(), Self::Error>

Writes a slice of Unicode scalar values.

§Parameters
  • chars: Characters to write in order.
§Errors

Returns an implementation-specific error when any character cannot be accepted by the sink.

Source

fn write_str(&mut self, text: &str) -> Result<(), Self::Error>

Writes a string slice.

§Parameters
  • text: Text to write.
§Errors

Returns an implementation-specific error when the text cannot be accepted by the sink.

Source

fn write_line(&mut self, line: &str) -> Result<(), Self::Error>

Writes a line followed by the configured line ending.

§Parameters
  • line: Line content to write. The configured line ending is appended.
§Errors

Returns an implementation-specific error when the line or line ending cannot be accepted by the sink.

Source

fn flush(&mut self) -> Result<(), Self::Error>

Flushes buffered text to the underlying sink.

§Errors

Returns an implementation-specific error when flushing fails.

Provided Methods§

Source

fn line_ending(&self) -> LineEnding

Returns the configured line ending for TextWrite::write_line.

§Returns

The configured line ending. Implementations default to LineEnding::Lf.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl TextWrite for String

Source§

type Error = Infallible

Source§

fn write_char(&mut self, ch: char) -> Result<(), Self::Error>

Source§

fn write_chars(&mut self, chars: &[char]) -> Result<(), Self::Error>

Source§

fn write_str(&mut self, text: &str) -> Result<(), Self::Error>

Source§

fn write_line(&mut self, line: &str) -> Result<(), Self::Error>

Source§

fn flush(&mut self) -> Result<(), Self::Error>

Implementors§