pub struct Span { /* private fields */ }
Implementations§
source§impl 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§
source§impl<'de> Deserialize<'de> for Span
impl<'de> Deserialize<'de> for Span
source§fn 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
source§impl Ord for Span
impl Ord for Span
source§impl PartialEq for Span
impl PartialEq for Span
source§impl PartialOrd for Span
impl PartialOrd for Span
1.0.0 · source§fn 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 moreimpl 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§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more