Trait add_ed::io::IO

source ·
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§

source

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

source

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

source

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

source

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

source

fn write_file( &mut self, path: &str, append: bool, data: LinesIter<'_> ) -> Result<usize, IOError>

Normal file write Returns number of bytes written

source

fn read_file(&mut self, path: &str, must_exist: bool) -> Result<String, IOError>

Normal file read

Implementors§