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

The returned string will be split into lines and added into the buffer. All line endings are converted into ‘\n’ when adding into the buffer.

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

The LinesIter contains string slices over ‘\n’ terminated lines. If you with to use “\r\n” line endings in the command input this should be handled in the IO implementation.

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

The LinesIter contains string slices over ‘\n’ terminated lines. If you with to use “\r\n” line endings in the command input this should be handled in the IO implementation.

The returned string will be split into lines and added into the buffer. All line endings are converted into ‘\n’ when adding into the buffer.

source

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

Normal file write

Returns number of bytes written

The LinesIter contains string slices over ‘\n’ terminated lines. If you with to write “\r\n” line endings into the file this should be handled in the IO implementation.

source

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

Normal file read

The returned string will be split into lines and added into the buffer. All line endings are converted into ‘\n’ when adding into the buffer.

Implementors§