[−][src]Struct grep_matcher::Match
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]
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]
fn clone(&self) -> 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]
fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
default fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
Feeds a slice of this type into the given [Hasher
]. Read more
impl Index<Match> for [u8]
[src]
impl Index<Match> for str
[src]
impl IndexMut<Match> for [u8]
[src]
Auto Trait Implementations
Blanket Implementations
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
impl<T> From for T
[src]
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,