syntree

Struct Span

Source
#[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>

Source

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);
Source

pub const fn point(at: I) -> Self
where I: Copy,

Construct a span corresponding to the given point.

§Examples
use syntree::Span;

assert_eq!(Span::point(4u32), Span::new(4u32, 4u32));
Source

pub fn join(&self, other: &Self) -> Self
where 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));
Source

pub fn is_empty(&self) -> bool
where 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());
Source

pub fn contains<U>(self, index: &U) -> bool
where 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));
Source§

impl<I> Span<I>
where I: Index,

Source

pub fn range(self) -> Range<usize>

Coerce into a ops::Range which is useful for slicing.

§Examples
use syntree::Span;

let a = Span::new(4u32, 8u32);

assert_eq!(a.range(), 4..8);
Source

pub fn len(&self) -> I::Length

The length of the span.

§Examples
use syntree::Span;

assert_eq!(Span::new(0u32, 0u32).len(), 0);
assert_eq!(Span::new(0u32, 10u32).len(), 10);

Trait Implementations§

Source§

impl<I: Clone> Clone for Span<I>

Source§

fn clone(&self) -> Span<I>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<I> Debug for Span<I>
where I: Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<I> Display for Span<I>
where I: Display,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<I: Hash> Hash for Span<I>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<I: Ord> Ord for Span<I>

Source§

fn cmp(&self, other: &Span<I>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<I> PartialEq<&Span<I>> for Span<I>
where I: PartialEq,

Source§

fn eq(&self, other: &&Span<I>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<A, B> PartialEq<Span<A>> for Span<B>
where B: PartialEq<A>,

Source§

fn eq(&self, other: &Span<A>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<I> PartialEq<Span<I>> for &Span<I>
where I: PartialEq,

Source§

fn eq(&self, other: &Span<I>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<I: PartialOrd> PartialOrd for Span<I>

Source§

fn partial_cmp(&self, other: &Span<I>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<I: Copy> Copy for Span<I>

Source§

impl<I: Eq> Eq for Span<I>

Auto Trait Implementations§

§

impl<I> Freeze for Span<I>
where I: Freeze,

§

impl<I> RefUnwindSafe for Span<I>
where I: RefUnwindSafe,

§

impl<I> Send for Span<I>
where I: Send,

§

impl<I> Sync for Span<I>
where I: Sync,

§

impl<I> Unpin for Span<I>
where I: Unpin,

§

impl<I> UnwindSafe for Span<I>
where I: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.