#[non_exhaustive]pub struct Span<I> {
pub start: I,
pub end: I,
}
Expand description
A span in the source code, akin to start..end
so the end of the span is
exclusive.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional
Struct { .. }
syntax; cannot be matched against without a wildcard ..
; and struct update syntax will not work.start: I
The start of the span.
end: I
The end of the span.
Implementations§
source§impl<I> Span<I>
impl<I> Span<I>
sourcepub const fn new(start: I, end: I) -> Self
pub const fn new(start: I, end: I) -> Self
Construct a new span.
Examples
use syntree::Span;
let span = Span::new(4u32, 8u32);
assert_eq!(span.start, 4);
assert_eq!(span.end, 8);
sourcepub const fn point(at: I) -> Selfwhere
I: Copy,
pub const fn point(at: I) -> Selfwhere I: Copy,
Construct a span corresponding to the given point.
Examples
use syntree::Span;
assert_eq!(Span::point(4u32), Span::new(4u32, 4u32));
sourcepub fn join(&self, other: &Self) -> Selfwhere
I: Copy + Ord,
pub fn join(&self, other: &Self) -> Selfwhere I: Copy + Ord,
Join the current span with another.
Examples
use syntree::Span;
let a = Span::new(4u32, 8u32);
let b = Span::new(5u32, 9u32);
let span = a.join(&b);
assert_eq!(span.start, 4);
assert_eq!(span.end, 9);
assert_eq!(span, b.join(&a));
sourcepub fn is_empty(&self) -> boolwhere
I: Eq,
pub fn is_empty(&self) -> boolwhere I: Eq,
Test if the span is empty.
Examples
use syntree::Span;
assert!(Span::new(0u32, 0u32).is_empty());
assert!(!Span::new(0u32, 10u32).is_empty());
sourcepub fn contains<U>(self, index: &U) -> boolwhere
I: PartialOrd<U>,
U: PartialOrd<I> + ?Sized,
pub fn contains<U>(self, index: &U) -> boolwhere I: PartialOrd<U>, U: PartialOrd<I> + ?Sized,
Test if span contains the given index.
Examples
use syntree::Span;
assert!(!Span::new(2u32, 2u32).contains(&2));
assert!(Span::new(2u32, 3u32).contains(&2));
assert!(!Span::new(2u32, 3u32).contains(&3));
Trait Implementations§
source§impl<I: Ord> Ord for Span<I>
impl<I: Ord> Ord for Span<I>
source§impl<I> PartialEq<&Span<I>> for Span<I>where
I: PartialEq,
impl<I> PartialEq<&Span<I>> for Span<I>where I: PartialEq,
source§impl<I> PartialEq<Span<I>> for &Span<I>where
I: PartialEq,
impl<I> PartialEq<Span<I>> for &Span<I>where I: PartialEq,
source§impl<I: PartialEq> PartialEq<Span<I>> for Span<I>
impl<I: PartialEq> PartialEq<Span<I>> for Span<I>
source§impl<I: PartialOrd> PartialOrd<Span<I>> for Span<I>
impl<I: PartialOrd> PartialOrd<Span<I>> for Span<I>
1.0.0 · source§fn 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