pub struct Span<T> {
pub start: usize,
pub end: usize,
/* private fields */
}Expand description
A window in a [T] sequence.
Note that the range covered by a Span is end-exclusive, meaning that the end index is not
included in the range covered by the Span. If you’re familiar with the Rust range syntax,
you could say the span covers the equivalent of start..end, not start..=end.
For a Span to be correct, its end index must be greater than or equal to its start
index. Creating or using a Span which does not follow this rule may lead to unexpected
behavior or panics.
Although specific to harper.js, this page may clear up any questions you have.
Fields§
§start: usizeThe start index of the span.
end: usizeThe end index of the span.
Note that Span represents an exclusive range. This means that a Span::new(0, 5) will
cover the values 0, 1, 2, 3, 4; it will not cover the 5.
Implementations§
Source§impl<T> Span<T>
impl<T> Span<T>
Sourcepub fn new_with_len(start: usize, len: usize) -> Self
pub fn new_with_len(start: usize, len: usize) -> Self
Creates a new Span from the provided start position and length.
Sourcepub fn overlaps_with(&self, other: Self) -> bool
pub fn overlaps_with(&self, other: Self) -> bool
Checks whether this span’s range overlaps with other.
Sourcepub fn try_get_content<'a>(&self, source: &'a [T]) -> Option<&'a [T]>
pub fn try_get_content<'a>(&self, source: &'a [T]) -> Option<&'a [T]>
Get the associated content. Will return None if the span is non-empty and any aspect is
invalid.
Sourcepub fn expand_to_include(&mut self, target: usize)
pub fn expand_to_include(&mut self, target: usize)
Expand the span by either modifying Self::start or Self::end to include the target
index.
Does nothing if the span already includes the target.
Sourcepub fn get_content<'a>(&self, source: &'a [T]) -> &'a [T]
pub fn get_content<'a>(&self, source: &'a [T]) -> &'a [T]
Get the associated content. Will panic if any aspect is invalid.
Sourcepub fn push_by(&mut self, by: usize)
pub fn push_by(&mut self, by: usize)
Add an amount to both Self::start and Self::end
Sourcepub fn pull_by(&mut self, by: usize)
pub fn pull_by(&mut self, by: usize)
Subtract an amount from both Self::start and Self::end
Sourcepub fn pushed_by(&self, by: usize) -> Self
pub fn pushed_by(&self, by: usize) -> Self
Add an amount to a copy of both Self::start and Self::end
Source§impl<T: Display + Debug> Span<T>
Additional functions for types that implement std::fmt::Debug and Display.
impl<T: Display + Debug> Span<T>
Additional functions for types that implement std::fmt::Debug and Display.
Source§impl Span<Token>
Functionality specific to Token spans.
impl Span<Token>
Functionality specific to Token spans.
Sourcepub fn to_char_span(&self, source_document_tokens: &[Token]) -> Span<char>
pub fn to_char_span(&self, source_document_tokens: &[Token]) -> Span<char>
Converts the Span<Token> into a Span<char>.
This requires knowing the character spans of the tokens covered by this
Span<Token>. Because of this, a reference to the source token sequence used to create
this span is required.
Trait Implementations§
Source§impl<'de, T> Deserialize<'de> for Span<T>
impl<'de, T> Deserialize<'de> for Span<T>
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl<T> Copy for Span<T>
impl<T: Eq> Eq for Span<T>
impl<T> StructuralPartialEq for Span<T>
Auto Trait Implementations§
impl<T> Freeze for Span<T>
impl<T> RefUnwindSafe for Span<T>where
T: RefUnwindSafe,
impl<T> Send for Span<T>where
T: Send,
impl<T> Sync for Span<T>where
T: Sync,
impl<T> Unpin for Span<T>where
T: Unpin,
impl<T> UnwindSafe for Span<T>where
T: UnwindSafe,
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§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more