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§
Source§impl Span
impl Span
Sourcepub fn new(start: Location, end: Location) -> Span
pub fn new(start: Location, end: Location) -> Span
Create a new span from a start and end Location
Sourcepub 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.
Sourcepub 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)));Sourcepub 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
Sourcepub 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§
Source§impl Ord for Span
impl Ord for Span
Source§impl PartialOrd for Span
impl PartialOrd for Span
Source§impl<'ast> Transformable<'ast> for Span
impl<'ast> Transformable<'ast> for Span
Source§impl Visitable for Span
impl Visitable for Span
Source§fn accept<'ast, V: Visitor<'ast>>(
&'ast self,
visitor: &mut V,
) -> ControlFlow<Break<V::Error>>
fn accept<'ast, V: Visitor<'ast>>( &'ast self, visitor: &mut V, ) -> ControlFlow<Break<V::Error>>
Accepts a borrowed
Visitor and traverses the AST starting at self invoking Visitor::enter and
Visitor::exit as nodes are entered and exiting respectively.Source§fn downcast_ref<Target: Visitable>(&self) -> Option<&Target>
fn downcast_ref<Target: Visitable>(&self) -> Option<&Target>
Tries to downcast
self as &Target.Source§fn downcast_mut<Target: Visitable>(&mut self) -> Option<&mut Target>
fn downcast_mut<Target: Visitable>(&mut self) -> Option<&mut Target>
Tries to downcast
self as &mut Target.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