You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
1.1 KiB
Rust
56 lines
1.1 KiB
Rust
//! The trait implemented by console structures.
|
|
|
|
use core::fmt;
|
|
|
|
/// Trait allowing a structure to be used as a console.
|
|
pub trait Console: Write + Read {}
|
|
|
|
/// Trait allowing to write to an object.
|
|
pub trait Write {
|
|
/// Write a single character.
|
|
fn write_char(&self, c: char);
|
|
|
|
/// Write a Rust format string.
|
|
fn write_fmt(&self, args: fmt::Arguments) -> fmt::Result;
|
|
|
|
/// Block until the last buffered character has been consumed.
|
|
fn flush(&self);
|
|
}
|
|
|
|
/// Trait allowing to read from an object.
|
|
pub trait Read {
|
|
// TODO: return an option?
|
|
/// Read a single character.
|
|
fn read_char(&self) -> char;
|
|
|
|
/// Clear the input buffer if any.
|
|
fn flush_input(&self);
|
|
}
|
|
|
|
|
|
/// A Dummy Console.
|
|
///
|
|
/// The DummyConsole implement the [`Console`] trait, and do nothing.
|
|
pub struct DummyConsole;
|
|
|
|
impl Write for DummyConsole {
|
|
fn write_char(&self, _c: char) {}
|
|
|
|
fn write_fmt(&self, _args: fmt::Arguments) -> fmt::Result {
|
|
Ok(())
|
|
}
|
|
|
|
fn flush(&self) {}
|
|
}
|
|
|
|
impl Read for DummyConsole {
|
|
fn read_char(&self) -> char {
|
|
' '
|
|
}
|
|
|
|
fn flush_input(&self) {}
|
|
}
|
|
|
|
|
|
impl Console for DummyConsole {}
|