[−][src]Struct codespan::Span
Implementations
impl Span
[src][−]
pub fn new(start: impl Into<ByteIndex>, end: impl Into<ByteIndex>) -> Span
[src][−]
Create a new span from a starting and ending span.
pub const fn initial() -> Span
[src][−]
Gives an empty span at the start of a source.
pub fn from_str(s: &str) -> Span
[src][−]
Measure the span of a string.
use codespan::{ByteIndex, Span}; let span = Span::from_str("hello"); assert_eq!(span, Span::new(0, 5));
pub fn merge(self, other: Span) -> Span
[src][−]
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));
pub fn disjoint(self, other: Span) -> bool
[src][−]
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));
pub fn start(self) -> ByteIndex
[src][−]
Get the starting byte index.
use codespan::{ByteIndex, Span}; let span = Span::new(0, 4); assert_eq!(span.start(), ByteIndex::from(0));
pub fn end(self) -> ByteIndex
[src][−]
Get the ending byte index.
use codespan::{ByteIndex, Span}; let span = Span::new(0, 4); assert_eq!(span.end(), ByteIndex::from(4));
Trait Implementations
impl Clone for Span
[src][+]
impl Copy for Span
[src]
impl Debug for Span
[src][+]
impl Default for Span
[src][+]
impl Display for Span
[src][+]
impl Eq for Span
[src]
impl<I> From<Range<I>> for Span where
I: Into<ByteIndex>,
[src][+]
I: Into<ByteIndex>,
impl From<Span> for Range<usize>
[src][+]
impl From<Span> for Range<RawIndex>
[src][+]
impl Hash for Span
[src][+]
impl Ord for Span
[src][+]
impl PartialEq<Span> for Span
[src][+]
impl PartialOrd<Span> for Span
[src][+]
impl StructuralEq for Span
[src]
impl StructuralPartialEq for Span
[src]
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
impl<T> Any for T where
T: 'static + ?Sized,
[src][+]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src][+]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src][+]
T: ?Sized,
impl<T> From<T> for T
[src][+]
impl<T, U> Into<U> for T where
U: From<T>,
[src][+]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src][+]
T: Clone,
impl<T> ToString for T where
T: Display + ?Sized,
[src][+]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src][+]
U: Into<T>,
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src][+]
U: TryFrom<T>,