Struct grep_matcher::Match [−][src]
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]
impl Match
pub fn new(start: usize, end: usize) -> Match
[src]
pub fn new(start: usize, end: usize) -> Match
pub fn zero(offset: usize) -> Match
[src]
pub fn zero(offset: usize) -> Match
Creates a zero width match at the given offset.
pub fn start(&self) -> usize
[src]
pub fn start(&self) -> usize
Return the start offset of this match.
pub fn end(&self) -> usize
[src]
pub fn end(&self) -> usize
Return the end offset of this match.
pub fn with_start(&self, start: usize) -> Match
[src]
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
.
pub fn with_end(&self, end: usize) -> Match
[src]
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
.
pub fn offset(&self, amount: usize) -> Match
[src]
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.
pub fn len(&self) -> usize
[src]
pub fn len(&self) -> usize
Returns the number of bytes in this match.
pub fn is_empty(&self) -> bool
[src]
pub fn is_empty(&self) -> bool
Returns true if and only if this match is empty.
Trait Implementations
impl Clone for Match
[src]
impl Clone for Match
fn clone(&self) -> Match
[src]
fn clone(&self) -> Match
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
impl Copy for Match
[src]
impl Copy for Match
impl Debug for Match
[src]
impl Debug for Match
fn fmt(&self, f: &mut Formatter) -> Result
[src]
fn fmt(&self, f: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl Eq for Match
[src]
impl Eq for Match
impl Hash for Match
[src]
impl Hash for Match
fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
fn hash<__H: Hasher>(&self, state: &mut __H)
Feeds this value into the given [Hasher
]. Read more
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
Feeds a slice of this type into the given [Hasher
]. Read more
impl PartialEq for Match
[src]
impl PartialEq for Match
fn eq(&self, other: &Match) -> bool
[src]
fn eq(&self, other: &Match) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Match) -> bool
[src]
fn ne(&self, other: &Match) -> bool
This method tests for !=
.
impl Index<Match> for [u8]
[src]
impl Index<Match> for [u8]
type Output = [u8]
The returned type after indexing.
fn index(&self, index: Match) -> &[u8]
[src]
fn index(&self, index: Match) -> &[u8]
Performs the indexing (container[index]
) operation.
impl IndexMut<Match> for [u8]
[src]
impl IndexMut<Match> for [u8]
fn index_mut(&mut self, index: Match) -> &mut [u8]
[src]
fn index_mut(&mut self, index: Match) -> &mut [u8]
Performs the mutable indexing (container[index]
) operation.
impl Index<Match> for str
[src]
impl Index<Match> for str