pub struct Sed { /* private fields */ }Expand description
A configured sed instance that can process text.
This is the recommended entry point for library usage. It wraps the
lower-level command::parse and engine::Engine with a builder-style
API.
§Examples
use sed_rs::Sed;
let output = Sed::new("s/hello/world/")
.unwrap()
.eval("hello\n")
.unwrap();
assert_eq!(output, "world\n");Implementations§
Source§impl Sed
impl Sed
Sourcepub fn new(script: &str) -> Result<Self>
pub fn new(script: &str) -> Result<Self>
Create a new Sed instance from a sed script string.
The script is validated (parsed and regex-compiled) eagerly; an error is returned immediately if the script is malformed.
Sourcepub fn quiet(&mut self, yes: bool) -> &mut Self
pub fn quiet(&mut self, yes: bool) -> &mut Self
Suppress automatic printing of the pattern space (equivalent to
the -n / --quiet flag).
Sourcepub fn null_data(&mut self, yes: bool) -> &mut Self
pub fn null_data(&mut self, yes: bool) -> &mut Self
Use NUL (\0) as the line delimiter instead of newline
(equivalent to -z / --null-data).
Sourcepub fn eval(&self, input: &str) -> Result<String>
pub fn eval(&self, input: &str) -> Result<String>
Evaluate the script against the given input string and return
the output as a String.
Sourcepub fn eval_bytes(&self, input: &[u8]) -> Result<String>
pub fn eval_bytes(&self, input: &[u8]) -> Result<String>
Evaluate the script against raw bytes and return the output as
a String.
Sourcepub fn eval_stream<R: Read, W: Write>(
&self,
reader: R,
writer: &mut W,
) -> Result<()>
pub fn eval_stream<R: Read, W: Write>( &self, reader: R, writer: &mut W, ) -> Result<()>
Evaluate the script by reading from a std::io::Read source
and writing to a std::io::Write sink.