Struct Span
pub struct Span { pub start: usize, pub end: usize }
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) -> Range<usize>Returns this span as a range.
fn is_empty(&self) -> boolReturns true when this span is empty. That is, when
start >= end.fn len(&self) -> usizeReturns the length of this span.
This returns
0in precisely the cases thatis_emptyreturnstrue.fn contains(&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, offset: usize) -> SpanReturns a new span with
offsetadded to this span'sstartandendvalues.Panics
This panics if adding
offsetto either part of thisSpanwould result in overflow.
Trait Implementations
impl Clone for Span
fn clone(&self) -> Self
impl Copy for Span
impl Debug for Span
fn fmt(&self, f: &mut Formatter<'_>) -> Result
impl Eq for Span
impl From<Range<usize>> for Span
fn from(range: Range<usize>) -> Span
impl Hash for Span
fn hash<__H: Hasher>(&self, state: &mut __H)
impl PartialEq for Span
fn eq(&self, other: &Self) -> bool
impl PartialEq<Range<usize>> for Span
fn eq(&self, range: &Range<usize>) -> bool
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 UnsafeUnpin for Span
impl UnwindSafe for Span
Blanket Implementations
impl<T> Any for Span
where
T: 'static + ?Sized,
fn type_id(&self) -> TypeId
impl<T> Borrow<T> for Span
where
T: ?Sized,
fn borrow(&self) -> &T
impl<T> BorrowMut<T> for Span
where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
impl<T> CloneToUninit for Span
where
T: Clone,
unsafe fn clone_to_uninit(&self, dest: *mut u8)
impl<T> From<T> for Span
fn from(t: T) -> TReturns the argument unchanged.
impl<T> ToOwned for Span
where
T: Clone,
type Owned = T;fn to_owned(&self) -> Tfn clone_into(&self, target: &mut T)
impl<T, U> Into<U> for Span
where
U: From<T>,
fn into(self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom<U> for Span
where
U: Into<T>,
type Error = never;fn try_from(value: U) -> Result<T, never>
impl<T, U> TryInto<U> for Span
where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error;fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>