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

Returns this span as a range.

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

Returns the length of this span.

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

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

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

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

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Converts to this type from the input type.
Converts to this type from the input type.
Feeds this value into the given Hasher. Read more
Feeds a slice of this type into the given Hasher. Read more
The returned type after indexing.
Performs the indexing (container[index]) operation. Read more
The returned type after indexing.
Performs the indexing (container[index]) operation. Read more
Performs the mutable indexing (container[index]) operation. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.