[][src]Struct grep_matcher::Match

pub struct Match { /* fields omitted */ }

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]);

Methods

impl Match[src]

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

Create a new match.

Panics

This function panics if start > end.

pub fn zero(offset: usize) -> Match[src]

Creates a zero width match at the given offset.

pub fn start(&self) -> usize[src]

Return the start offset of this match.

pub fn end(&self) -> usize[src]

Return the end offset of this match.

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

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

Panics

This method panics if start > self.end.

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

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

Panics

This method panics if self.start > end.

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

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.

pub fn len(&self) -> usize[src]

Returns the number of bytes in this match.

pub fn is_empty(&self) -> bool[src]

Returns true if and only if this match is empty.

Trait Implementations

impl Eq for Match[src]

impl Copy for Match[src]

impl PartialEq<Match> for Match[src]

impl Clone for Match[src]

default fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

impl Debug for Match[src]

impl Hash for Match[src]

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

Feeds a slice of this type into the given [Hasher]. Read more

impl Index<Match> for [u8][src]

type Output = [u8]

The returned type after indexing.

impl Index<Match> for str[src]

type Output = str

The returned type after indexing.

impl IndexMut<Match> for [u8][src]

Auto Trait Implementations

impl Send for Match

impl Sync for Match

Blanket Implementations

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

impl<T> From for T[src]

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.