[][src]Struct nu_source::Span

pub struct Span { /* fields omitted */ }

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 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<'a>(&self, source: &'a str) -> String[src]

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

pub fn spanned_string<'a>(&self, source: &'a 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]

impl Copy for Span[src]

impl Debug for Span[src]

impl Default for Span[src]

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

impl Eq for Span[src]

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

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

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

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

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

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

impl From<Span> for Tag[src]

impl From<Span> for Range<usize>[src]

impl From<Tag> for Span[src]

impl HasSpan for Span[src]

impl Hash for Span[src]

impl Ord for Span[src]

impl PartialEq<Span> for Span[src]

impl PartialEq<usize> for Span[src]

impl PartialOrd<Span> for Span[src]

impl PartialOrd<usize> for Span[src]

impl PrettyDebugWithSource for Span[src]

impl Serialize for Span[src]

impl StructuralEq for Span[src]

impl StructuralPartialEq for Span[src]

Auto Trait Implementations

Blanket Implementations

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

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

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

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

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

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

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

type Owned = T

The resulting type after obtaining ownership.

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.

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.