Struct Span
pub struct Span {
pub start: Location,
pub end: Location,
}Expand description
A span represents a linear portion of the input string (start, end)
See Spanned for more information.
Fields§
§start: Location§end: LocationImplementations§
§impl Span
impl Span
pub const fn empty() -> Span
pub const fn empty() -> Span
Returns an empty span (0, 0) -> (0, 0)
Empty spans represent no knowledge of source location See Spanned for more information.
pub fn union(&self, other: &Span) -> Span
pub fn union(&self, other: &Span) -> Span
Returns the smallest Span that contains both self and other
If either span is Span::empty, the other span is returned
§Examples
// line 1, column1 -> line 2, column 5
let span1 = Span::new(Location::new(1, 1), Location::new(2, 5));
// line 2, column 3 -> line 3, column 7
let span2 = Span::new(Location::new(2, 3), Location::new(3, 7));
// Union of the two is the min/max of the two spans
// line 1, column 1 -> line 3, column 7
let union = span1.union(&span2);
assert_eq!(union, Span::new(Location::new(1, 1), Location::new(3, 7)));pub fn union_opt(&self, other: &Option<Span>) -> Span
pub fn union_opt(&self, other: &Option<Span>) -> Span
Same as Span::union for Option<Span>
If other is None, self is returned
pub fn union_iter<I>(iter: I) -> Spanwhere
I: IntoIterator<Item = Span>,
pub fn union_iter<I>(iter: I) -> Spanwhere
I: IntoIterator<Item = Span>,
Return the Span::union of all spans in the iterator
If the iterator is empty, an empty span is returned
§Example
let spans = vec![
Span::new(Location::new(1, 1), Location::new(2, 5)),
Span::new(Location::new(2, 3), Location::new(3, 7)),
Span::new(Location::new(3, 1), Location::new(4, 2)),
];
// line 1, column 1 -> line 4, column 2
assert_eq!(
Span::union_iter(spans),
Span::new(Location::new(1, 1), Location::new(4, 2))
);Trait Implementations§
§impl Ord for Span
impl Ord for Span
§impl PartialOrd for Span
impl PartialOrd for Span
§impl VisitMut for Span
impl VisitMut for Span
fn visit<V>(&mut self, visitor: &mut V) -> ControlFlow<<V as VisitorMut>::Break>where
V: VisitorMut,
impl Copy for Span
impl Eq for Span
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 UnwindSafe for Span
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Checks if this value is equivalent to the given key. Read more
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Checks if this value is equivalent to the given key. Read more
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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>
Converts
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>
Converts
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