pub struct Span { /* private fields */ }
Implementations
sourceimpl Span
impl Span
sourcepub fn new(start: impl Into<ByteIndex>, end: impl Into<ByteIndex>) -> Span
pub fn new(start: impl Into<ByteIndex>, end: impl Into<ByteIndex>) -> Span
Create a new span from a starting and ending span.
sourcepub fn from_str(s: &str) -> Span
pub fn from_str(s: &str) -> Span
Measure the span of a string.
use codespan::{ByteIndex, Span};
let span = Span::from_str("hello");
assert_eq!(span, Span::new(0, 5));
sourcepub fn merge(self, other: Span) -> Span
pub fn merge(self, other: Span) -> Span
Combine two spans by taking the start of the earlier span and the end of the later span.
Note: this will work even if the two spans are disjoint.
If this doesn’t make sense in your application, you should handle it yourself.
In that case, you can use Span::disjoint
as a convenience function.
use codespan::Span;
let span1 = Span::new(0, 4);
let span2 = Span::new(10, 16);
assert_eq!(Span::merge(span1, span2), Span::new(0, 16));
sourcepub fn disjoint(self, other: Span) -> bool
pub fn disjoint(self, other: Span) -> bool
A helper function to tell whether two spans do not overlap.
use codespan::Span;
let span1 = Span::new(0, 4);
let span2 = Span::new(10, 16);
assert!(span1.disjoint(span2));
Trait Implementations
sourceimpl<'de> Deserialize<'de> for Span
impl<'de> Deserialize<'de> for Span
sourcefn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
sourceimpl Ord for Span
impl Ord for Span
sourceimpl PartialOrd<Span> for Span
impl PartialOrd<Span> for Span
sourcefn partial_cmp(&self, other: &Span) -> Option<Ordering>
fn partial_cmp(&self, other: &Span) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
impl Copy for Span
impl Eq for Span
impl StructuralEq for Span
impl StructuralPartialEq for Span
Auto Trait Implementations
impl RefUnwindSafe for Span
impl Send for Span
impl Sync for Span
impl Unpin for Span
impl UnwindSafe for Span
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more