Skip to main content

CharIo

Trait CharIo 

Source
pub trait CharIo {
    type Error;

    // Required methods
    fn get_char(&mut self) -> Result<Option<char>, Self::Error>;
    fn put_char(&mut self, c: char) -> Result<(), Self::Error>;

    // Provided method
    fn write_str(&mut self, s: &str) -> Result<(), Self::Error> { ... }
}
Expand description

Platform-agnostic character I/O trait. Implementations provide non-blocking character I/O with platform-specific buffering.

Required Associated Types§

Source

type Error

Platform-specific error type

Required Methods§

Source

fn get_char(&mut self) -> Result<Option<char>, Self::Error>

Read character if available (non-blocking).

Returns Ok(Some(char)) if available, Ok(None) otherwise.

Source

fn put_char(&mut self, c: char) -> Result<(), Self::Error>

Write character to output buffer (must not block indefinitely).

Provided Methods§

Source

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

Write string to output buffer.

Default calls put_char() per character. Override for efficiency if needed.

Implementors§