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

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

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

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

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

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

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

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

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.

Returns the start position of the current Span.

Returns the end position of the current Span.

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

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

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

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

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

Deserialize this value from the given Serde deserializer. Read more

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Feeds this value into the given Hasher. Read more

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

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

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

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

This method tests for !=.

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

This method tests for !=.

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

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

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

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

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

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

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

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

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

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

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

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

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

recently added

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.