Struct gluon_base::pos::Span
source · pub struct Span<I> { /* private fields */ }
Expand description
A region of code in a source file
Implementations
sourceimpl<I> Span<I>where
I: Ord,
impl<I> Span<I>where
I: Ord,
sourcepub fn new(start: I, end: I) -> Span<I>
pub fn new(start: I, end: I) -> Span<I>
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));
pub fn map<F, J>(self, f: F) -> Span<J>where
F: FnMut(I) -> J,
J: Ord,
sourceimpl<I> Span<I>where
I: Index,
impl<I> Span<I>where
I: Index,
sourcepub fn subspan(
&self,
begin: <I as Index>::Offset,
end: <I as Index>::Offset
) -> Span<I>
pub fn subspan(
&self,
begin: <I as Index>::Offset,
end: <I as Index>::Offset
) -> Span<I>
Makes a span from offsets relative to the start of this span.
sourcepub fn from_offset(start: I, off: <I as Index>::Offset) -> Span<I>
pub fn from_offset(start: I, off: <I as Index>::Offset) -> Span<I>
Create a new span from a byte start and an offset
sourcepub fn with_start(self, start: I) -> Span<I>
pub fn with_start(self, start: I) -> Span<I>
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)));
sourcepub fn with_end(self, end: I) -> Span<I>
pub fn with_end(self, end: I) -> Span<I>
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)));
sourcepub fn contains(self, other: Span<I>) -> bool
pub fn contains(self, other: Span<I>) -> bool
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);
sourcepub fn containment(self, pos: I) -> Ordering
pub fn containment(self, pos: I) -> Ordering
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);
sourcepub fn containment_exclusive(self, pos: I) -> Ordering
pub fn containment_exclusive(self, pos: I) -> Ordering
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);
sourcepub fn to(self, end: Span<I>) -> Span<I>
pub fn to(self, end: Span<I>) -> Span<I>
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)));
sourcepub fn between(self, end: Span<I>) -> Span<I>
pub fn between(self, end: Span<I>) -> Span<I>
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)));
sourcepub fn until(self, end: Span<I>) -> Span<I>
pub fn until(self, end: Span<I>) -> Span<I>
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
sourceimpl<I> Ord for Span<I>where
I: Ord,
impl<I> Ord for Span<I>where
I: Ord,
1.21.0 · sourcefn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 · sourcefn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
1.50.0 · sourcefn clamp(self, min: Self, max: Self) -> Selfwhere
Self: Sized + PartialOrd<Self>,
fn clamp(self, min: Self, max: Self) -> Selfwhere
Self: Sized + PartialOrd<Self>,
sourceimpl<I> PartialEq<Span<I>> for Span<I>where
I: PartialEq<I>,
impl<I> PartialEq<Span<I>> for Span<I>where
I: PartialEq<I>,
sourceimpl<I> PartialOrd<Span<I>> for Span<I>where
I: PartialOrd<I>,
impl<I> PartialOrd<Span<I>> for Span<I>where
I: PartialOrd<I>,
sourcefn partial_cmp(&self, other: &Span<I>) -> Option<Ordering>
fn partial_cmp(&self, other: &Span<I>) -> Option<Ordering>
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more