Struct grep_matcher::Match

source ·
pub struct Match { /* private fields */ }
Expand description

The type of a match.

The type of a match is a possibly empty range pointing to a contiguous block of addressable memory.

Every Match is guaranteed to satisfy the invariant that start <= end.

Indexing

This type is structurally identical to std::ops::Range<usize>, but is a bit more ergonomic for dealing with match indices. In particular, this type implements Copy and provides methods for building new Match values based on old Match values. Finally, the invariant that start is always less than or equal to end is enforced.

A Match can be used to slice a &[u8], &mut [u8] or &str using range notation. e.g.,

use grep_matcher::Match;

let m = Match::new(2, 5);
let bytes = b"abcdefghi";
assert_eq!(b"cde", &bytes[m]);

Implementations§

source§

impl Match

source

pub fn new(start: usize, end: usize) -> Match

Create a new match.

Panics

This function panics if start > end.

source

pub fn zero(offset: usize) -> Match

Creates a zero width match at the given offset.

source

pub fn start(&self) -> usize

Return the start offset of this match.

source

pub fn end(&self) -> usize

Return the end offset of this match.

source

pub fn with_start(&self, start: usize) -> Match

Return a new match with the start offset replaced with the given value.

Panics

This method panics if start > self.end.

source

pub fn with_end(&self, end: usize) -> Match

Return a new match with the end offset replaced with the given value.

Panics

This method panics if self.start > end.

source

pub fn offset(&self, amount: usize) -> Match

Offset this match by the given amount and return a new match.

This adds the given offset to the start and end of this match, and returns the resulting match.

Panics

This panics if adding the given amount to either the start or end offset would result in an overflow.

source

pub fn len(&self) -> usize

Returns the number of bytes in this match.

source

pub fn is_empty(&self) -> bool

Returns true if and only if this match is empty.

Trait Implementations§

source§

impl Clone for Match

source§

fn clone(&self) -> Match

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Match

source§

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

Formats the value using the given formatter. Read more
source§

impl Hash for Match

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl Index<Match> for [u8]

§

type Output = [u8]

The returned type after indexing.
source§

fn index(&self, index: Match) -> &[u8]

Performs the indexing (container[index]) operation. Read more
source§

impl Index<Match> for str

§

type Output = str

The returned type after indexing.
source§

fn index(&self, index: Match) -> &str

Performs the indexing (container[index]) operation. Read more
source§

impl IndexMut<Match> for [u8]

source§

fn index_mut(&mut self, index: Match) -> &mut [u8]

Performs the mutable indexing (container[index]) operation. Read more
source§

impl PartialEq for Match

source§

fn eq(&self, other: &Match) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Copy for Match

source§

impl Eq for Match

source§

impl StructuralEq for Match

source§

impl StructuralPartialEq for Match

Auto Trait Implementations§

§

impl RefUnwindSafe for Match

§

impl Send for Match

§

impl Sync for Match

§

impl Unpin for Match

§

impl UnwindSafe for Match

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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.