pub struct Span {
pub start: usize,
pub end: usize,
}
Expand description
A representation of a span reported by a regex engine.
A span corresponds to the starting and ending byte offsets of a contiguous region of bytes. The starting offset is inclusive while the ending offset is exclusive. That is, a span is a half-open interval.
A span is used to report the offsets of a match, but it is also used to
convey which region of a haystack should be searched via routines like
Input::span
.
This is basically equivalent to a std::ops::Range<usize>
, except this
type implements Copy
which makes it more ergonomic to use in the context
of this crate. Like a range, this implements Index
for [u8]
and str
,
and IndexMut
for [u8]
. For convenience, this also impls From<Range>
,
which means things like Span::from(5..10)
work.
Fields§
§start: usize
The start offset of the span, inclusive.
end: usize
The end offset of the span, exclusive.
Implementations§
Source§impl Span
impl Span
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true when this span is empty. That is, when start >= end
.
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the length of this span.
This returns 0
in precisely the cases that is_empty
returns true
.
Trait Implementations§
impl Copy for Span
impl Eq for Span
impl StructuralPartialEq for Span
Auto Trait Implementations§
impl Freeze for Span
impl RefUnwindSafe for Span
impl Send for Span
impl Sync for Span
impl Unpin for Span
impl UnwindSafe for Span
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)