pub trait ReadExt: Read {
// Provided method
fn pipe(self, cmd: Cmd) -> Pipeline
where Self: Sized + Send + 'static { ... }
}
Expand description
Extension trait for std::io::Read
to enable fluent piping to commands.
This trait allows any Read
-implementing type to be piped directly to commands,
enabling intuitive method chaining for I/O operations.
§Examples
use scripty::*;
use std::fs::File;
// Pipe file contents through a command pipeline
let file = File::open("data.txt")?;
let result = file.pipe(cmd!("grep", "pattern"))
.pipe(cmd!("sort"))
.pipe(cmd!("uniq"))
.output()?;
// Process large files efficiently with streaming
use std::io::BufReader;
let large_file = File::open("huge_dataset.txt")?;
let reader = BufReader::new(large_file);
reader.pipe(cmd!("awk", "{sum += $1} END {print sum}"))
.run()?;
// Chain with existing pipeline methods
use std::io::Cursor;
let data = Cursor::new(b"line1\nline2\nline3\n");
data.pipe(cmd!("sort"))
.pipe(cmd!("wc", "-l"))
.output()?;
Provided Methods§
Sourcefn pipe(self, cmd: Cmd) -> Pipeline
fn pipe(self, cmd: Cmd) -> Pipeline
Pipe this reader’s data to a command’s stdin.
This method creates a pipeline where the reader’s data becomes the input
for the specified command. The resulting Pipeline
can be further chained
with additional commands or executed with methods like run()
, output()
,
or write_to()
.
§Type Requirements
The reader must be Send + 'static
to support the pipeline’s threading model.
This is automatically satisfied by most standard library types like File
,
BufReader
, Cursor
, etc.
§Examples
use scripty::*;
use std::fs::File;
// Basic piping
let file = File::open("input.txt")?;
file.pipe(cmd!("sort")).run()?;
// Get output
let file = File::open("numbers.txt")?;
let sum = file.pipe(cmd!("awk", "{sum += $1} END {print sum}"))
.output()?;
// Chain multiple commands
let file = File::open("log.txt")?;
let errors = file.pipe(cmd!("grep", "ERROR"))
.pipe(cmd!("wc", "-l"))
.output()?;