Struct safe_regex::Matcher10

source ·
pub struct Matcher10<F>
where F: Fn(&[u8]) -> Option<[Range<usize>; 10]>,
{ /* private fields */ }
Expand description

A compiled regular expression with 10 capturing groups.

This is a zero-length type. The regex! macro generates a Rust type that implements the regular expression. This struct holds that type.

Implementations§

source§

impl<F> Matcher10<F>
where F: Fn(&[u8]) -> Option<[Range<usize>; 10]>,

source

pub fn new(f: F) -> Self

This is used internally by the regex! macro.

source

pub fn is_match(&self, data: &[u8]) -> bool

Returns true if data matches the regular expression, otherwise returns false.

This is a whole-string match. For sub-string search, put .* at the beginning and end of the regex.

§Example
use safe_regex::{regex, Matcher0};
let matcher: Matcher0<_> = regex!(br"[abc][0-9]*");
assert!(matcher.is_match(b"a42"));
assert!(!matcher.is_match(b"X"));
source

pub fn match_ranges( &self, data: &[u8] ) -> Option<(Range<usize>, Range<usize>, Range<usize>, Range<usize>, Range<usize>, Range<usize>, Range<usize>, Range<usize>, Range<usize>, Range<usize>)>

Executes the regular expression against the byte slice data.

Returns Some((Range<u32>,Range<u32>,...)) if the expression matched all of the bytes in data. The tuple fields are ranges of bytes in data that matched capturing groups in the expression. A capturing group that matches no bytes will produce as a zero-length range.

This is a whole-string match. For sub-string search, put .* at the beginning and end of the regex.

Returns None if the expression did not match data.

§Example
use safe_regex::{regex, Matcher3};
let matcher: Matcher3<_> = regex!(br"([abc])([0-9]*)(suffix)?");
let (prefix, digits, suffix) = matcher.match_ranges(b"a42").unwrap();
assert_eq!(0..1_usize, prefix);
assert_eq!(1..3_usize, digits);
assert_eq!(0..0_usize, suffix);
source

pub fn match_slices<'d>( &self, data: &'d [u8] ) -> Option<(&'d [u8], &'d [u8], &'d [u8], &'d [u8], &'d [u8], &'d [u8], &'d [u8], &'d [u8], &'d [u8], &'d [u8])>

Executes the regular expression against the byte slice data.

Returns Some((&[u8],&[u8],...)) if the expression matched all of the bytes in data. The tuple fields are slices of data that matched capturing groups in the expression.

This is a whole-string match. For sub-string search, put .* at the beginning and end of the regex.

Returns None if the expression did not match data.

§Example
use safe_regex::{regex, Matcher3};
let matcher: Matcher3<_> = regex!(br"([abc])([0-9]*)(suffix)?");
let (prefix, digits, suffix) = matcher.match_slices(b"a42").unwrap();
assert_eq!(b"a", prefix);
assert_eq!(b"42", digits);
assert!(suffix.is_empty());

Trait Implementations§

source§

impl<F: Fn(&[u8]) -> Option<[Range<usize>; 10]>> IsMatch for Matcher10<F>

source§

fn is_match(&self, data: &[u8]) -> bool

Returns true if data matches the regular expression, otherwise returns false. Read more
source§

fn assert_match(&self, data: &[u8])

Panics Read more
source§

fn assert_no_match(&self, data: &[u8])

Panics Read more

Auto Trait Implementations§

§

impl<F> Freeze for Matcher10<F>
where F: Freeze,

§

impl<F> RefUnwindSafe for Matcher10<F>
where F: RefUnwindSafe,

§

impl<F> Send for Matcher10<F>
where F: Send,

§

impl<F> Sync for Matcher10<F>
where F: Sync,

§

impl<F> Unpin for Matcher10<F>
where F: Unpin,

§

impl<F> UnwindSafe for Matcher10<F>
where F: UnwindSafe,

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>,

§

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>,

§

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.