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: Location
Implementations§
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: IntoIterator<Item = Span>>(iter: I) -> Span
pub fn union_iter<I: IntoIterator<Item = Span>>(iter: I) -> 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<'de> Deserialize<'de> for Span
impl<'de> Deserialize<'de> for Span
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>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Ord for Span
impl Ord for Span
Source§impl PartialOrd for Span
impl PartialOrd for Span
Source§impl VisitMut for Span
impl VisitMut for Span
fn visit<V: VisitorMut>(&mut self, visitor: &mut V) -> ControlFlow<V::Break>
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