Struct gluon_base::pos::Span

source ·
pub struct Span<I> { /* private fields */ }
Expand description

A region of code in a source file

Implementations

Create a new span

use codespan::{ByteIndex, Span};

let span = Span::new(ByteIndex(3), ByteIndex(6));
assert_eq!(span.start(), ByteIndex(3));
assert_eq!(span.end(), ByteIndex(6));

start and end are reordered to maintain the invariant that start <= end

use codespan::{ByteIndex, Span};

let span = Span::new(ByteIndex(6), ByteIndex(3));
assert_eq!(span.start(), ByteIndex(3));
assert_eq!(span.end(), ByteIndex(6));

Get the start index

Get the end index

Makes a span from offsets relative to the start of this span.

Create a new span from a byte start and an offset

Return a new span with the low byte position replaced with the supplied byte position

use codespan::{ByteIndex, Span};

let span = Span::new(ByteIndex(3), ByteIndex(6));
assert_eq!(span.with_start(ByteIndex(2)), Span::new(ByteIndex(2), ByteIndex(6)));
assert_eq!(span.with_start(ByteIndex(5)), Span::new(ByteIndex(5), ByteIndex(6)));
assert_eq!(span.with_start(ByteIndex(7)), Span::new(ByteIndex(6), ByteIndex(7)));

Return a new span with the high byte position replaced with the supplied byte position

use codespan::{ByteIndex, Span};

let span = Span::new(ByteIndex(3), ByteIndex(6));
assert_eq!(span.with_end(ByteIndex(7)), Span::new(ByteIndex(3), ByteIndex(7)));
assert_eq!(span.with_end(ByteIndex(5)), Span::new(ByteIndex(3), ByteIndex(5)));
assert_eq!(span.with_end(ByteIndex(2)), Span::new(ByteIndex(2), ByteIndex(3)));

Return true if self fully encloses other.

use codespan::{ByteIndex, Span};

let a = Span::new(ByteIndex(5), ByteIndex(8));

assert_eq!(a.contains(a), true);
assert_eq!(a.contains(Span::new(ByteIndex(6), ByteIndex(7))), true);
assert_eq!(a.contains(Span::new(ByteIndex(6), ByteIndex(10))), false);
assert_eq!(a.contains(Span::new(ByteIndex(3), ByteIndex(6))), false);

Return Equal if self contains pos, otherwise it returns Less if pos is before start or Greater if pos is after or at end.

use codespan::{ByteIndex, Span};
use std::cmp::Ordering::*;

let a = Span::new(ByteIndex(5), ByteIndex(8));

assert_eq!(a.containment(ByteIndex(4)), Less);
assert_eq!(a.containment(ByteIndex(5)), Equal);
assert_eq!(a.containment(ByteIndex(6)), Equal);
assert_eq!(a.containment(ByteIndex(8)), Equal);
assert_eq!(a.containment(ByteIndex(9)), Greater);

Return Equal if self contains pos, otherwise it returns Less if pos is before start or Greater if pos is strictly after end.

use codespan::{ByteIndex, Span};
use std::cmp::Ordering::*;

let a = Span::new(ByteIndex(5), ByteIndex(8));

assert_eq!(a.containment_exclusive(ByteIndex(4)), Less);
assert_eq!(a.containment_exclusive(ByteIndex(5)), Equal);
assert_eq!(a.containment_exclusive(ByteIndex(6)), Equal);
assert_eq!(a.containment_exclusive(ByteIndex(8)), Greater);
assert_eq!(a.containment_exclusive(ByteIndex(9)), Greater);

Return a Span that would enclose both self and end.

self     ~~~~~~~
end                     ~~~~~~~~
returns  ~~~~~~~~~~~~~~~~~~~~~~~
use codespan::{ByteIndex, Span};

let a = Span::new(ByteIndex(2), ByteIndex(5));
let b = Span::new(ByteIndex(10), ByteIndex(14));

assert_eq!(a.to(b), Span::new(ByteIndex(2), ByteIndex(14)));

Return a Span between the end of self to the beginning of end.

self     ~~~~~~~
end                     ~~~~~~~~
returns         ~~~~~~~~~
use codespan::{ByteIndex, Span};

let a = Span::new(ByteIndex(2), ByteIndex(5));
let b = Span::new(ByteIndex(10), ByteIndex(14));

assert_eq!(a.between(b), Span::new(ByteIndex(5), ByteIndex(10)));

Return a Span between the beginning of self to the beginning of end.

self     ~~~~~~~
end                     ~~~~~~~~
returns  ~~~~~~~~~~~~~~~~
use codespan::{ByteIndex, Span};

let a = Span::new(ByteIndex(2), ByteIndex(5));
let b = Span::new(ByteIndex(10), ByteIndex(14));

assert_eq!(a.until(b), Span::new(ByteIndex(2), ByteIndex(10)));

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
Formats the value using the given formatter. 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 !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. 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

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

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
Converts the given value to a String. 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.