Struct Span
struct Span { ... }
A representation of a range in a haystack.
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. Indeed, Span exists only because Range<usize> does
not implement Copy. 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.
There are no constraints on the values of a span. It is, for example, legal
to create a span where start > end.
Fields
start: usizeThe start offset of the span, inclusive.
end: usizeThe end offset of the span, exclusive.
Implementations
impl Span
fn range(self: &Self) -> Range<usize>Returns this span as a range.
fn is_empty(self: &Self) -> boolReturns true when this span is empty. That is, when
start >= end.fn len(self: &Self) -> usizeReturns the length of this span.
This returns
0in precisely the cases thatis_emptyreturnstrue.fn contains(self: &Self, offset: usize) -> boolReturns true when the given offset is contained within this span.
Note that an empty span contains no offsets and will always return false.
fn offset(self: &Self, offset: usize) -> SpanReturns a new span with
offsetadded to this span'sstartandendvalues.
impl Clone for Span
fn clone(self: &Self) -> Span
impl Copy for Span
impl Debug for Span
fn fmt(self: &Self, f: &mut Formatter<'_>) -> Result
impl Eq for Span
impl Freeze for Span
impl From for Span
fn from(range: Range<usize>) -> Span
impl Hash for Span
fn hash<__H: $crate::hash::Hasher>(self: &Self, state: &mut __H)
impl PartialEq for Span
fn eq(self: &Self, range: &Range<usize>) -> bool
impl PartialEq for Span
fn eq(self: &Self, other: &Span) -> bool
impl RefUnwindSafe for Span
impl Send for Span
impl StructuralPartialEq for Span
impl Sync for Span
impl Unpin for Span
impl UnsafeUnpin for Span
impl UnwindSafe for Span
impl<T> Any for Span
fn type_id(self: &Self) -> TypeId
impl<T> Borrow for Span
fn borrow(self: &Self) -> &T
impl<T> BorrowMut for Span
fn borrow_mut(self: &mut Self) -> &mut T
impl<T> CloneToUninit for Span
unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)
impl<T> From for Span
fn from(t: T) -> TReturns the argument unchanged.
impl<T> ToOwned for Span
fn to_owned(self: &Self) -> Tfn clone_into(self: &Self, target: &mut T)
impl<T, U> Into for Span
fn into(self: Self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom for Span
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto for Span
fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>