Struct NoExpand

pub struct NoExpand<'s>(pub &'s [u8]);

A helper type for forcing literal string replacement.

It can be used with routines like Regex::replace and Regex::replace_all to do a literal string replacement without expanding $name to their corresponding capture groups. This can be both convenient (to avoid escaping $, for example) and faster (since capture groups don't need to be found).

's is the lifetime of the literal string to use.

Example

use regex::bytes::{NoExpand, Regex};

let re = Regex::new(r"(?<last>[^,\s]+),\s+(\S+)").unwrap();
let result = re.replace(b"Springsteen, Bruce", NoExpand(b"$2 $last"));
assert_eq!(result, &b"$2 $last"[..]);

Fields

0: &'s [u8]

Trait Implementations

impl<'s> Clone for NoExpand<'s>

fn clone(&self) -> Self

impl<'s> Debug for NoExpand<'s>

fn fmt(&self, f: &mut Formatter<'_>) -> Result

impl<'s> Replacer for NoExpand<'s>

fn replace_append(&mut self, &Captures<'_>, dst: &mut Vec<u8>)
fn no_expansion(&mut self) -> Option<Cow<'_, [u8]>>

Auto Trait Implementations

impl<'s> Freeze for NoExpand<'s>

impl<'s> RefUnwindSafe for NoExpand<'s>

impl<'s> Send for NoExpand<'s>

impl<'s> Sync for NoExpand<'s>

impl<'s> Unpin for NoExpand<'s>

impl<'s> UnsafeUnpin for NoExpand<'s>

impl<'s> UnwindSafe for NoExpand<'s>

Blanket Implementations

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

impl<T> Borrow<T> for NoExpand<'s> where T: ?Sized,

impl<T> BorrowMut<T> for NoExpand<'s> where T: ?Sized,

impl<T> CloneToUninit for NoExpand<'s> where T: Clone,

impl<T> From<T> for NoExpand<'s>

impl<T> ToOwned for NoExpand<'s> where T: Clone,

impl<T, U> Into<U> for NoExpand<'s> where U: From<T>,

impl<T, U> TryFrom<U> for NoExpand<'s> where U: Into<T>,

impl<T, U> TryInto<U> for NoExpand<'s> where U: TryFrom<T>,