Struct aho_corasick::Span

source ·
pub struct Span {
    pub start: usize,
    pub end: usize,
}
Expand description

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: usize

The start offset of the span, inclusive.

§end: usize

The end offset of the span, exclusive.

Implementations§

source§

impl Span

source

pub fn range(&self) -> Range<usize>

Returns this span as a range.

source

pub fn is_empty(&self) -> bool

Returns true when this span is empty. That is, when start >= end.

source

pub fn len(&self) -> usize

Returns the length of this span.

This returns 0 in precisely the cases that is_empty returns true.

source

pub fn contains(&self, offset: usize) -> bool

Returns true when the given offset is contained within this span.

Note that an empty span contains no offsets and will always return false.

source

pub fn offset(&self, offset: usize) -> Span

Returns a new span with offset added to this span’s start and end values.

Trait Implementations§

source§

impl Clone for Span

source§

fn clone(&self) -> Span

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Span

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl From<Range<usize>> for Span

source§

fn from(range: Range<usize>) -> Span

Converts to this type from the input type.
source§

impl From<Span> for Range<usize>

source§

fn from(span: Span) -> Range<usize>

Converts to this type from the input type.
source§

impl Hash for Span

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl Index<Span> for [u8]

§

type Output = [u8]

The returned type after indexing.
source§

fn index(&self, index: Span) -> &[u8]

Performs the indexing (container[index]) operation. Read more
source§

impl Index<Span> for str

§

type Output = str

The returned type after indexing.
source§

fn index(&self, index: Span) -> &str

Performs the indexing (container[index]) operation. Read more
source§

impl IndexMut<Span> for [u8]

source§

fn index_mut(&mut self, index: Span) -> &mut [u8]

Performs the mutable indexing (container[index]) operation. Read more
source§

impl PartialEq<Range<usize>> for Span

source§

fn eq(&self, range: &Range<usize>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<Span> for Range<usize>

source§

fn eq(&self, span: &Span) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<Span> for Span

source§

fn eq(&self, other: &Span) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Copy for Span

source§

impl Eq for Span

source§

impl StructuralEq for Span

source§

impl StructuralPartialEq for Span

Auto Trait Implementations§

§

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> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.