Struct syntree::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) -> Selfwhere 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) -> 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));
source

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());
source

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));
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) -> Selfwhere Self: Sized,

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

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

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

fn clamp(self, min: Self, max: Self) -> Selfwhere Self: Sized + PartialOrd<Self>,

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method 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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<I: PartialEq> PartialEq<Span<I>> for Span<I>

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<I: PartialOrd> PartialOrd<Span<I>> 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

This method 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

This method 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

This method 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

This method 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>

source§

impl<I> StructuralEq for Span<I>

source§

impl<I> StructuralPartialEq for Span<I>

Auto Trait Implementations§

§

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 Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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 Twhere T: Clone,

§

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 Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

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

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

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.