Struct nu_source::Span[][src]

pub struct Span { /* fields omitted */ }
Expand description

A Span is metadata which indicates the start and end positions.

Spans are combined with AnchorLocations to form another type of metadata, a Tag. A Span’s end position must be greater than or equal to its start position.

Implementations

impl Span[src]

pub fn default() -> Self[src]

Creates a default new Span that has 0 start and 0 end.

pub fn unknown() -> Span[src]

Creates a new Span that has 0 start and 0 end.

pub fn from_list(list: &[impl HasSpan]) -> Span[src]

pub fn new(start: usize, end: usize) -> Span[src]

Creates a new Span from start and end inputs. The end parameter must be greater than or equal to the start parameter.

pub fn for_char(pos: usize) -> Span[src]

Creates a Span with a length of 1 from the given position.

Example

let char_span = Span::for_char(5);

assert_eq!(char_span.start(), 5);
assert_eq!(char_span.end(), 6);

pub fn contains(&self, pos: usize) -> bool[src]

Returns a bool indicating if the given position falls inside the current Span.

Example

let span = Span::new(2, 8);

assert_eq!(span.contains(5), true);
assert_eq!(span.contains(8), false);
assert_eq!(span.contains(100), false);

pub fn since(&self, other: impl Into<Span>) -> Span[src]

Returns a new Span by merging an earlier Span with the current Span.

The resulting Span will have the same start position as the given Span and same end as the current Span.

Example

let original_span = Span::new(4, 6);
let earlier_span = Span::new(1, 3);
let merged_span = origin_span.since(earlier_span);

assert_eq!(merged_span.start(), 1);
assert_eq!(merged_span.end(), 6);

pub fn until(&self, other: impl Into<Span>) -> Span[src]

Returns a new Span by merging a later Span with the current Span.

The resulting Span will have the same start position as the current Span and same end as the given Span.

Example

let original_span = Span::new(4, 6);
let later_span = Span::new(9, 11);
let merged_span = origin_span.until(later_span);

assert_eq!(merged_span.start(), 4);
assert_eq!(merged_span.end(), 11);

pub fn until_option(&self, other: Option<impl Into<Span>>) -> Span[src]

Returns a new Span by merging a later Span with the current Span.

If the given Span is of the None variant, A Span with the same values as the current Span is returned.

pub fn string(&self, source: &str) -> String[src]

pub fn spanned_slice<'a>(&self, source: &'a str) -> Spanned<&'a str>[src]

pub fn spanned_string(&self, source: &str) -> Spanned<String>[src]

pub fn start(&self) -> usize[src]

Returns the start position of the current Span.

pub fn end(&self) -> usize[src]

Returns the end position of the current Span.

pub fn is_unknown(&self) -> bool[src]

Returns a bool if the current Span indicates an “unknown” position.

Example

let unknown_span = Span::unknown();
let known_span = Span::new(4, 6);

assert_eq!(unknown_span.is_unknown(), true);
assert_eq!(known_span.is_unknown(), false);

pub fn is_closed(&self) -> bool[src]

Returns a bool if the current Span does not cover.

Example

//  make clean
//  ----
//  (0,4)
//
//       ^(5,5)

let make_span = Span::new(0,4);
let clean_span = Span::new(5,5);

assert_eq!(make_span.is_closed(), false);
assert_eq!(clean_span.is_closed(), true);

pub fn slice<'a>(&self, source: &'a str) -> &'a str[src]

Returns a slice of the input that covers the start and end of the current Span.

Trait Implementations

impl Clone for Span[src]

fn clone(&self) -> Span[src]

Returns a copy of the value. Read more

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl Debug for Span[src]

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

Formats the value using the given formatter. Read more

impl Default for Span[src]

fn default() -> Span[src]

Returns the “default value” for a type. Read more

impl<'de> Deserialize<'de> for Span[src]

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
    __D: Deserializer<'de>, 
[src]

Deserialize this value from the given Serde deserializer. Read more

impl From<&'_ Range<usize>> for Span[src]

fn from(input: &Range<usize>) -> Span[src]

Performs the conversion.

impl From<&'_ Span> for Tag[src]

fn from(span: &Span) -> Self[src]

Performs the conversion.

impl From<&'_ Span> for Span[src]

fn from(span: &Span) -> Span[src]

Performs the conversion.

impl From<&'_ Tag> for Span[src]

fn from(tag: &Tag) -> Self[src]

Performs the conversion.

impl From<(usize, usize)> for Span[src]

fn from(input: (usize, usize)) -> Span[src]

Performs the conversion.

impl From<Option<Span>> for Span[src]

fn from(input: Option<Span>) -> Span[src]

Performs the conversion.

impl From<Span> for Tag[src]

fn from(span: Span) -> Self[src]

Performs the conversion.

impl From<Tag> for Span[src]

fn from(tag: Tag) -> Self[src]

Performs the conversion.

impl HasSpan for Span[src]

fn span(&self) -> Span[src]

impl Hash for Span[src]

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

Feeds this value into the given Hasher. Read more

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

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

impl Ord for Span[src]

fn cmp(&self, other: &Span) -> Ordering[src]

This method returns an Ordering between self and other. Read more

#[must_use]
fn max(self, other: Self) -> Self
1.21.0[src]

Compares and returns the maximum of two values. Read more

#[must_use]
fn min(self, other: Self) -> Self
1.21.0[src]

Compares and returns the minimum of two values. Read more

#[must_use]
fn clamp(self, min: Self, max: Self) -> Self
1.50.0[src]

Restrict a value to a certain interval. Read more

impl PartialEq<Span> for Span[src]

fn eq(&self, other: &Span) -> bool[src]

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &Span) -> bool[src]

This method tests for !=.

impl PartialEq<usize> for Span[src]

fn eq(&self, other: &usize) -> bool[src]

This method tests for self and other values to be equal, and is used by ==. Read more

#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests for !=.

impl PartialOrd<Span> for Span[src]

fn partial_cmp(&self, other: &Span) -> Option<Ordering>[src]

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

#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests less than (for self and other) and is used by the < operator. Read more

#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl PartialOrd<usize> for Span[src]

fn partial_cmp(&self, other: &usize) -> Option<Ordering>[src]

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

#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests less than (for self and other) and is used by the < operator. Read more

#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl PrettyDebugWithSource for Span[src]

fn pretty_debug(&self, source: &str) -> DebugDocBuilder[src]

fn refined_pretty_debug(
    &self,
    _refine: PrettyDebugRefineKind,
    source: &str
) -> DebugDocBuilder
[src]

fn debug(&self, source: impl Into<Text>) -> String where
    Self: Clone
[src]

fn debuggable(self, source: impl Into<Text>) -> DebuggableWithSource<Self>[src]

impl Serialize for Span[src]

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error> where
    __S: Serializer
[src]

Serialize this value into the given Serde serializer. Read more

impl Copy for Span[src]

impl Eq for Span[src]

impl StructuralEq for Span[src]

impl StructuralPartialEq for Span[src]

Auto Trait Implementations

impl RefUnwindSafe for Span

impl Send for Span

impl Sync for Span

impl Unpin for Span

impl UnwindSafe for Span

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

pub fn to_owned(&self) -> T[src]

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

pub fn clone_into(&self, target: &mut T)[src]

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

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

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

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

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

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

Performs the conversion.

impl<T> DeserializeOwned for T where
    T: for<'de> Deserialize<'de>, 
[src]