pub struct Span {
pub start: ByteIndex,
pub end: ByteIndex,
}
Expand description
A span corresponding to a range in the source file being parsed.
Fields§
§start: ByteIndex
The start of the span in bytes.
end: ByteIndex
The end of the span in bytes.
Implementations§
Source§impl Span
impl Span
Sourcepub fn new<S, E>(start: S, end: E) -> Self
pub fn new<S, E>(start: S, end: E) -> Self
Construct a new span.
§Examples
use rune::ast::Span;
let span = Span::new(42, 50);
assert!(span < Span::new(100, 101));
Sourcepub fn point<P>(pos: P) -> Self
pub fn point<P>(pos: P) -> Self
Get a span corresponding to a single point where both start and end are the same byte offset.
§Examples
use rune::ast::Span;
assert_eq!(Span::point(42), Span::new(42, 42));
Sourcepub const fn empty() -> Self
pub const fn empty() -> Self
Constant function to build an empty span.
§Examples
use rune::ast::Span;
assert_eq!(Span::empty(), Span::new(0, 0));
Sourcepub fn join(self, other: Self) -> Self
pub fn join(self, other: Self) -> Self
Join two spans creating the larger of the two spans.
§Examples
use rune::ast::Span;
let a = Span::new(10, 12);
let b = Span::new(20, 22);
assert_eq!(a.join(b), Span::new(10, 22));
Sourcepub fn narrow(self, amount: impl Into<ByteIndex>) -> Self
pub fn narrow(self, amount: impl Into<ByteIndex>) -> Self
Narrow the span with the given amount.
If the narrowing causes the span to become empty, the resulting span will reflect the starting point of the narrowed span.
§Examples
use rune::ast::Span;
assert_eq!(Span::new(10, 12).narrow(4), Span::new(10, 10));
assert_eq!(Span::new(5, 15).narrow(2), Span::new(7, 13));
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
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,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
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
Compare self to
key
and return true
if they are equal.