Skip to main content

Sed

Struct Sed 

Source
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

Source

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.

Source

pub fn quiet(&mut self, yes: bool) -> &mut Self

Suppress automatic printing of the pattern space (equivalent to the -n / --quiet flag).

Source

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).

Source

pub fn eval(&self, input: &str) -> Result<String>

Evaluate the script against the given input string and return the output as a String.

Source

pub fn eval_bytes(&self, input: &[u8]) -> Result<String>

Evaluate the script against raw bytes and return the output as a String.

Source

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.

Auto Trait Implementations§

§

impl Freeze for Sed

§

impl RefUnwindSafe for Sed

§

impl Send for Sed

§

impl Sync for Sed

§

impl Unpin for Sed

§

impl UnwindSafe for Sed

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.