pub trait IO {
// Required methods
fn run_command(
&mut self,
ui: &mut UILock<'_>,
command: String
) -> Result<(), IOError>;
fn run_read_command(
&mut self,
ui: &mut UILock<'_>,
command: String
) -> Result<String, IOError>;
fn run_write_command(
&mut self,
ui: &mut UILock<'_>,
command: String,
input: LinesIter<'_>
) -> Result<usize, IOError>;
fn run_transform_command(
&mut self,
ui: &mut UILock<'_>,
command: String,
input: LinesIter<'_>
) -> Result<String, IOError>;
fn write_file(
&mut self,
path: &str,
append: bool,
data: LinesIter<'_>
) -> Result<usize, IOError>;
fn read_file(
&mut self,
path: &str,
must_exist: bool
) -> Result<String, IOError>;
}Expand description
Trait that abstracts file interactions and running shell commands
Intended to allow modifying how and where system interactions occur. Example cases for replacing this:
- Dummy IO to prevent filesystem modifications while testing.
- SSH forwarding to save to remote system and run commands remotely.
- Restricted IO to forbid command running and restrict file paths.
Required Methods§
sourcefn run_command(
&mut self,
ui: &mut UILock<'_>,
command: String
) -> Result<(), IOError>
fn run_command( &mut self, ui: &mut UILock<'_>, command: String ) -> Result<(), IOError>
Run a lone command (unrelated from the buffer)
Stdin, Stdout and Stderr passed through to UI
sourcefn run_read_command(
&mut self,
ui: &mut UILock<'_>,
command: String
) -> Result<String, IOError>
fn run_read_command( &mut self, ui: &mut UILock<'_>, command: String ) -> Result<String, IOError>
Run a read command, collecting stdout to add into buffer
Stdin and Stderr should be passed through to UI
sourcefn run_write_command(
&mut self,
ui: &mut UILock<'_>,
command: String,
input: LinesIter<'_>
) -> Result<usize, IOError>
fn run_write_command( &mut self, ui: &mut UILock<'_>, command: String, input: LinesIter<'_> ) -> Result<usize, IOError>
Run a write command, receiving part of buffer via stdin
Stdout and Stderr should be passed through to UI Returns number of bytes written
sourcefn run_transform_command(
&mut self,
ui: &mut UILock<'_>,
command: String,
input: LinesIter<'_>
) -> Result<String, IOError>
fn run_transform_command( &mut self, ui: &mut UILock<'_>, command: String, input: LinesIter<'_> ) -> Result<String, IOError>
Run a transform command, taking part of buffer via stdin and returning it via stdout.
Stderr should be passed through to UI