pub trait IoProvider {
// Required methods
fn read_char(&mut self, port: PortId) -> Result<char, IoErrorKind>;
fn peek_char(&mut self, port: PortId) -> Result<char, IoErrorKind>;
fn char_ready(&mut self, port: PortId) -> Result<bool, IoErrorKind>;
fn write_char(&mut self, port: PortId, c: char) -> Result<(), IoErrorKind>;
fn write_str(&mut self, port: PortId, s: &str) -> Result<(), IoErrorKind>;
fn flush(&mut self, port: PortId) -> Result<(), IoErrorKind>;
fn close_port(&mut self, port: PortId) -> Result<(), IoErrorKind>;
fn is_input_port(&self, port: PortId) -> bool;
fn is_output_port(&self, port: PortId) -> bool;
// Provided methods
fn open_input_string(&mut self, _s: &str) -> Result<PortId, IoErrorKind> { ... }
fn open_output_string(&mut self) -> Result<PortId, IoErrorKind> { ... }
fn get_output_string(&self, _port: PortId) -> Result<&str, IoErrorKind> { ... }
}Expand description
Trait for providing I/O operations to the evaluator.
This trait defines the boundary between the pure no_std evaluator
and platform-specific I/O implementations. The grift_std crate
provides a standard implementation backed by Rust’s std::io.
§Implementor Notes
PortId::STDIN,PortId::STDOUT, andPortId::STDERRshould always be accepted as valid ports.- Implementations may support additional dynamically-opened ports
(e.g. file ports) by returning fresh
PortIdvalues.
Required Methods§
Sourcefn read_char(&mut self, port: PortId) -> Result<char, IoErrorKind>
fn read_char(&mut self, port: PortId) -> Result<char, IoErrorKind>
Read a single character from the specified input port.
Sourcefn peek_char(&mut self, port: PortId) -> Result<char, IoErrorKind>
fn peek_char(&mut self, port: PortId) -> Result<char, IoErrorKind>
Peek at the next character without consuming it.
Sourcefn char_ready(&mut self, port: PortId) -> Result<bool, IoErrorKind>
fn char_ready(&mut self, port: PortId) -> Result<bool, IoErrorKind>
Return true if a character is ready on the input port.
Sourcefn write_char(&mut self, port: PortId, c: char) -> Result<(), IoErrorKind>
fn write_char(&mut self, port: PortId, c: char) -> Result<(), IoErrorKind>
Write a single character to the specified output port.
Sourcefn write_str(&mut self, port: PortId, s: &str) -> Result<(), IoErrorKind>
fn write_str(&mut self, port: PortId, s: &str) -> Result<(), IoErrorKind>
Write a string slice to the specified output port.
Sourcefn close_port(&mut self, port: PortId) -> Result<(), IoErrorKind>
fn close_port(&mut self, port: PortId) -> Result<(), IoErrorKind>
Close the specified port.
Sourcefn is_input_port(&self, port: PortId) -> bool
fn is_input_port(&self, port: PortId) -> bool
Return true if the port is an input port.
Sourcefn is_output_port(&self, port: PortId) -> bool
fn is_output_port(&self, port: PortId) -> bool
Return true if the port is an output port.
Provided Methods§
Sourcefn open_input_string(&mut self, _s: &str) -> Result<PortId, IoErrorKind>
fn open_input_string(&mut self, _s: &str) -> Result<PortId, IoErrorKind>
Open an input port that reads from the given string.
Returns a fresh PortId for the new port.
Default: returns IoErrorKind::Unsupported.
Sourcefn open_output_string(&mut self) -> Result<PortId, IoErrorKind>
fn open_output_string(&mut self) -> Result<PortId, IoErrorKind>
Open an output port that accumulates characters into a string buffer.
Returns a fresh PortId for the new port.
Default: returns IoErrorKind::Unsupported.
Sourcefn get_output_string(&self, _port: PortId) -> Result<&str, IoErrorKind>
fn get_output_string(&self, _port: PortId) -> Result<&str, IoErrorKind>
Retrieve the accumulated string from an output string port.
The port must have been created by open_output_string.
Default: returns IoErrorKind::Unsupported.