Struct codespan::Span [−][src]
pub struct Span<I> { /* fields omitted */ }
A region of code in a source file
Methods
impl<I: Ord> Span<I>
[src]
impl<I: Ord> Span<I>
pub fn new(start: I, end: I) -> Span<I>
[src]
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,
[src]
pub fn map<F, J>(self, f: F) -> Span<J> where
F: FnMut(I) -> J,
J: Ord,
impl<I> Span<I>
[src]
impl<I> Span<I>
impl<I: Index> Span<I>
[src]
impl<I: Index> Span<I>
pub fn subspan(&self, begin: I::Offset, end: I::Offset) -> Span<I>
[src]
pub fn subspan(&self, begin: I::Offset, end: I::Offset) -> Span<I>
Makes a span from offsets relative to the start of this span.
pub fn from_offset(start: I, off: I::Offset) -> Span<I>
[src]
pub fn from_offset(start: I, off: I::Offset) -> Span<I>
Create a new span from a byte start and an offset
pub fn with_start(self, start: I) -> Span<I>
[src]
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)));
pub fn with_end(self, end: I) -> Span<I>
[src]
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)));
pub fn contains(self, other: Span<I>) -> bool
[src]
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);
pub fn containment(self, pos: I) -> Ordering
[src]
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);
pub fn containment_exclusive(self, pos: I) -> Ordering
[src]
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);
pub fn to(self, end: Span<I>) -> Span<I>
[src]
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)));
pub fn between(self, end: Span<I>) -> Span<I>
[src]
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)));
pub fn until(self, end: Span<I>) -> Span<I>
[src]
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
impl<I: Debug> Debug for Span<I>
[src]
impl<I: Debug> Debug for Span<I>
fn fmt(&self, f: &mut Formatter) -> Result
[src]
fn fmt(&self, f: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl<I: Clone> Clone for Span<I>
[src]
impl<I: Clone> Clone for Span<I>
fn clone(&self) -> Span<I>
[src]
fn clone(&self) -> Span<I>
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
impl<I: Copy> Copy for Span<I>
[src]
impl<I: Copy> Copy for Span<I>
impl<I: Default> Default for Span<I>
[src]
impl<I: Default> Default for Span<I>
impl<I: PartialEq> PartialEq for Span<I>
[src]
impl<I: PartialEq> PartialEq for Span<I>
fn eq(&self, other: &Span<I>) -> bool
[src]
fn eq(&self, other: &Span<I>) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Span<I>) -> bool
[src]
fn ne(&self, other: &Span<I>) -> bool
This method tests for !=
.
impl<I: Eq> Eq for Span<I>
[src]
impl<I: Eq> Eq for Span<I>
impl<I: Ord> Ord for Span<I>
[src]
impl<I: Ord> Ord for Span<I>
fn cmp(&self, other: &Span<I>) -> Ordering
[src]
fn cmp(&self, other: &Span<I>) -> Ordering
This method returns an Ordering
between self
and other
. Read more
fn max(self, other: Self) -> Self
1.21.0[src]
fn max(self, other: Self) -> Self
Compares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self
1.21.0[src]
fn min(self, other: Self) -> Self
Compares and returns the minimum of two values. Read more
impl<I: PartialOrd> PartialOrd for Span<I>
[src]
impl<I: PartialOrd> PartialOrd for Span<I>
fn partial_cmp(&self, other: &Span<I>) -> Option<Ordering>
[src]
fn partial_cmp(&self, other: &Span<I>) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
fn lt(&self, other: &Span<I>) -> bool
[src]
fn lt(&self, other: &Span<I>) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
fn le(&self, other: &Span<I>) -> bool
[src]
fn le(&self, other: &Span<I>) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
fn gt(&self, other: &Span<I>) -> bool
[src]
fn gt(&self, other: &Span<I>) -> bool
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
fn ge(&self, other: &Span<I>) -> bool
[src]
fn ge(&self, other: &Span<I>) -> bool
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl<I: Display> Display for Span<I>
[src]
impl<I: Display> Display for Span<I>