pub struct Span { /* private fields */ }Expand description
Range of bytes in a source file.
This is very similar to the Range<usize> type unless it is not an iterator
and implements the Copy trait.
Implementations
sourceimpl Span
impl Span
sourcepub fn new(start: usize, end: usize) -> Self
pub fn new(start: usize, end: usize) -> Self
Creates a new Span by providing the index of its starting byte (included) and ending byte (excluded).
If the end position is lower than the start position,
then the start position is used as ending position instead.
sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Checks if the span is empty.
Returns true if the start position is equal to the end position,
and false otherwise.
The end position can never be lower than the start position.
sourcepub fn end(&self) -> usize
pub fn end(&self) -> usize
Returns the index of the first byte after the span.
This can never be lower than Self::start.
sourcepub fn contains(&self, index: usize) -> bool
pub fn contains(&self, index: usize) -> bool
Checks if the given byte index if included in the span.
sourcepub fn set_start(&mut self, start: usize)
pub fn set_start(&mut self, start: usize)
Sets the index of the first byte in the span.
If the end position of the span is lower that start,
then it is also changed into start.
sourcepub fn set_end(&mut self, end: usize)
pub fn set_end(&mut self, end: usize)
Sets the index of the first byte after the span.
If end is lower that the start position, the start position is used instead.
sourcepub fn union(&self, other: Self) -> Self
pub fn union(&self, other: Self) -> Self
Computes the union of two spans.
If the two spans do not overlap, all the positions in between will be included in the resulting span.
sourcepub fn append(&mut self, other: Self)
pub fn append(&mut self, other: Self)
Extend this span to include other.
This is the in-place version of union.
sourcepub fn inter(&self, other: Self) -> Self
pub fn inter(&self, other: Self) -> Self
Computes the intersection of two spans.
If the two spans do not overlap, then the empty span located at the start of the most advanced span (maximum of the start of the two spans) is returned.
Trait Implementations
sourceimpl IntoIterator for Span
impl IntoIterator for Span
sourceimpl<'a> IntoIterator for &'a Span
impl<'a> IntoIterator for &'a Span
sourceimpl Ord for Span
impl Ord for Span
sourceimpl PartialOrd<Span> for Span
impl PartialOrd<Span> for Span
sourcefn partial_cmp(&self, other: &Span) -> Option<Ordering>
fn partial_cmp(&self, other: &Span) -> Option<Ordering>
This method returns an ordering between self and other values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self and other) and is used by the <=
operator. Read more
impl Copy for Span
impl Eq for Span
impl StructuralEq for Span
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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more