nut_shell/
io.rs

1//! Character I/O abstraction for platform-agnostic input/output.
2//!
3//! The `CharIo` trait provides non-blocking character-level I/O operations.
4
5/// Platform-agnostic character I/O trait.
6/// Implementations provide non-blocking character I/O with platform-specific buffering.
7pub trait CharIo {
8    /// Platform-specific error type
9    type Error;
10
11    /// Read character if available (non-blocking).
12    ///
13    /// Returns `Ok(Some(char))` if available, `Ok(None)` otherwise.
14    fn get_char(&mut self) -> Result<Option<char>, Self::Error>;
15
16    /// Write character to output buffer (must not block indefinitely).
17    fn put_char(&mut self, c: char) -> Result<(), Self::Error>;
18
19    /// Write string to output buffer.
20    ///
21    /// Default calls `put_char()` per character. Override for efficiency if needed.
22    fn write_str(&mut self, s: &str) -> Result<(), Self::Error> {
23        for c in s.chars() {
24            self.put_char(c)?;
25        }
26        Ok(())
27    }
28}