pub struct StdIoProvider { /* private fields */ }Expand description
An IoProvider implementation backed by Rust’s standard I/O.
Supports the three well-known ports:
PortId | Direction | Backing |
|---|---|---|
STDIN | input | std::io::stdin() |
STDOUT | output | std::io::stdout() |
STDERR | output | std::io::stderr() |
Additionally supports dynamically opened string ports.
Implementations§
Source§impl StdIoProvider
impl StdIoProvider
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new StdIoProvider.
Trait Implementations§
Source§impl Default for StdIoProvider
impl Default for StdIoProvider
Source§impl IoProvider for StdIoProvider
impl IoProvider for StdIoProvider
Source§fn read_char(&mut self, port: PortId) -> IoResult<char>
fn read_char(&mut self, port: PortId) -> IoResult<char>
Read a single character from the specified input port.
Source§fn peek_char(&mut self, port: PortId) -> IoResult<char>
fn peek_char(&mut self, port: PortId) -> IoResult<char>
Peek at the next character without consuming it.
Source§fn char_ready(&mut self, port: PortId) -> IoResult<bool>
fn char_ready(&mut self, port: PortId) -> IoResult<bool>
Return
true if a character is ready on the input port.Source§fn write_char(&mut self, port: PortId, c: char) -> IoResult<()>
fn write_char(&mut self, port: PortId, c: char) -> IoResult<()>
Write a single character to the specified output port.
Source§fn write_str(&mut self, port: PortId, s: &str) -> IoResult<()>
fn write_str(&mut self, port: PortId, s: &str) -> IoResult<()>
Write a string slice to the specified output port.
Source§fn is_input_port(&self, port: PortId) -> bool
fn is_input_port(&self, port: PortId) -> bool
Return
true if the port is an input port.Source§fn is_output_port(&self, port: PortId) -> bool
fn is_output_port(&self, port: PortId) -> bool
Return
true if the port is an output port.Source§fn is_port_open(&self, port: PortId) -> bool
fn is_port_open(&self, port: PortId) -> bool
Return
true if the port is still open.
Default: returns true (assumes ports are open unless overridden).Source§fn open_input_string(&mut self, s: &str) -> IoResult<PortId>
fn open_input_string(&mut self, s: &str) -> IoResult<PortId>
Open an input port that reads from the given string. Read more
Source§fn open_output_string(&mut self) -> IoResult<PortId>
fn open_output_string(&mut self) -> IoResult<PortId>
Open an output port that accumulates characters into a string buffer. Read more
Source§fn get_output_string(&self, port: PortId) -> IoResult<&str>
fn get_output_string(&self, port: PortId) -> IoResult<&str>
Retrieve the accumulated string from an output string port. Read more
Source§fn file_exists(&self, path: &str) -> IoResult<bool>
fn file_exists(&self, path: &str) -> IoResult<bool>
Check whether a file exists at the given path.
Default: returns
IoErrorKind::Unsupported.Source§fn delete_file(&mut self, path: &str) -> IoResult<()>
fn delete_file(&mut self, path: &str) -> IoResult<()>
Delete the file at the given path.
Default: returns
IoErrorKind::Unsupported.Source§fn read_file(&mut self, path: &str) -> IoResult<&str>
fn read_file(&mut self, path: &str) -> IoResult<&str>
Read the entire contents of a file as a string.
Default: returns
IoErrorKind::Unsupported.Source§fn command_line_count(&self) -> IoResult<usize>
fn command_line_count(&self) -> IoResult<usize>
Return the number of command-line arguments.
Default: returns
IoErrorKind::Unsupported.Source§fn command_line_arg(&self, index: usize) -> IoResult<&str>
fn command_line_arg(&self, index: usize) -> IoResult<&str>
Return the command-line argument at the given index.
Default: returns
IoErrorKind::Unsupported.Source§fn get_environment_variable(&mut self, name: &str) -> IoResult<Option<&str>>
fn get_environment_variable(&mut self, name: &str) -> IoResult<Option<&str>>
Retrieve the value of an environment variable by name.
Returns
Ok(Some(value)) if found, Ok(None) if not set.
Default: returns IoErrorKind::Unsupported.Source§fn environment_variables_count(&mut self) -> IoResult<usize>
fn environment_variables_count(&mut self) -> IoResult<usize>
Return the number of environment variables.
Must be called before
environment_variable_at
to snapshot the current environment.
Default: returns IoErrorKind::Unsupported.Source§fn environment_variable_at(&self, index: usize) -> IoResult<(&str, &str)>
fn environment_variable_at(&self, index: usize) -> IoResult<(&str, &str)>
Return the environment variable name and value at the given index.
environment_variables_count must be
called first to snapshot the environment.
Default: returns IoErrorKind::Unsupported.Source§fn exit_process(&mut self, code: i32) -> IoResult<()>
fn exit_process(&mut self, code: i32) -> IoResult<()>
Exit the process with the given status code.
Default: returns
IoErrorKind::Unsupported.Source§fn emergency_exit_process(&mut self, code: i32) -> IoResult<()>
fn emergency_exit_process(&mut self, code: i32) -> IoResult<()>
Emergency exit the process (no cleanup) with the given status code.
Default: returns
IoErrorKind::Unsupported.Source§fn is_textual_port(&self, port: PortId) -> bool
fn is_textual_port(&self, port: PortId) -> bool
Return
true if the port is a textual port.
Default: returns true for any valid input or output port.Source§fn is_binary_port(&self, _port: PortId) -> bool
fn is_binary_port(&self, _port: PortId) -> bool
Return
true if the port is a binary port.
Default: returns false (all ports are textual by default).Auto Trait Implementations§
impl Freeze for StdIoProvider
impl RefUnwindSafe for StdIoProvider
impl Send for StdIoProvider
impl Sync for StdIoProvider
impl Unpin for StdIoProvider
impl UnwindSafe for StdIoProvider
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more