use core::ops::Range;
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub struct MatchBytes<'t> {
pub(crate) bytes: &'t [u8],
pub(crate) match_start: usize,
pub(crate) match_end: usize,
}
impl<'t> MatchBytes<'t> {
#[inline]
pub fn start(&self) -> usize {
self.match_start
}
#[inline]
pub fn end(&self) -> usize {
self.match_end
}
#[inline]
pub fn range(&self) -> Range<usize> {
self.match_start..self.match_end
}
#[inline]
pub fn as_bytes(&self) -> &'t [u8] {
&self.bytes[self.match_start..self.match_end]
}
pub(crate) fn new(bytes: &'t [u8], start: usize, end: usize) -> MatchBytes<'t> {
MatchBytes {
bytes,
match_start: start,
match_end: end,
}
}
}
impl<'t> From<MatchBytes<'t>> for &'t [u8] {
fn from(m: MatchBytes<'t>) -> &'t [u8] {
m.as_bytes()
}
}
impl<'t> From<MatchBytes<'t>> for Range<usize> {
fn from(m: MatchBytes<'t>) -> Range<usize> {
m.range()
}
}