pub struct Span { /* private fields */ }
Expand description
A Span
is metadata which indicates the start and end positions.
Span
s are combined with AnchorLocation
s to form another type of metadata, a Tag
.
A Span
’s end position must be greater than or equal to its start position.
Implementations
sourceimpl Span
impl Span
pub fn from_list(list: &[impl HasSpan]) -> Span
sourcepub fn new(start: usize, end: usize) -> Span
pub fn new(start: usize, end: usize) -> Span
Creates a new Span
from start and end inputs. The end parameter must be greater than or equal to the start parameter.
pub fn new_option(start: usize, end: usize) -> Option<Span>
sourcepub fn for_char(pos: usize) -> Span
pub fn for_char(pos: usize) -> Span
Creates a Span
with a length of 1 from the given position.
Example
let char_span = Span::for_char(5);
assert_eq!(char_span.start(), 5);
assert_eq!(char_span.end(), 6);
sourcepub fn contains(&self, pos: usize) -> bool
pub fn contains(&self, pos: usize) -> bool
Returns a bool indicating if the given position falls inside the current Span
.
Example
let span = Span::new(2, 8);
assert_eq!(span.contains(5), true);
assert_eq!(span.contains(8), false);
assert_eq!(span.contains(100), false);
sourcepub fn since(&self, other: impl Into<Span>) -> Span
pub fn since(&self, other: impl Into<Span>) -> Span
Returns a new Span by merging an earlier Span with the current Span.
The resulting Span will have the same start position as the given Span and same end as the current Span.
Example
let original_span = Span::new(4, 6);
let earlier_span = Span::new(1, 3);
let merged_span = origin_span.since(earlier_span);
assert_eq!(merged_span.start(), 1);
assert_eq!(merged_span.end(), 6);
sourcepub fn until(&self, other: impl Into<Span>) -> Span
pub fn until(&self, other: impl Into<Span>) -> Span
Returns a new Span by merging a later Span with the current Span.
The resulting Span will have the same start position as the current Span and same end as the given Span.
Example
let original_span = Span::new(4, 6);
let later_span = Span::new(9, 11);
let merged_span = origin_span.until(later_span);
assert_eq!(merged_span.start(), 4);
assert_eq!(merged_span.end(), 11);
pub fn merge(&self, other: impl Into<Span>) -> Span
sourcepub fn until_option(&self, other: Option<impl Into<Span>>) -> Span
pub fn until_option(&self, other: Option<impl Into<Span>>) -> Span
Returns a new Span by merging a later Span with the current Span.
If the given Span is of the None variant, A Span with the same values as the current Span is returned.
pub fn string(&self, source: &str) -> String
pub fn spanned_slice<'a>(&self, source: &'a str) -> Spanned<&'a str>
pub fn spanned_string(&self, source: &str) -> Spanned<String>
sourcepub fn is_unknown(&self) -> bool
pub fn is_unknown(&self) -> bool
Returns a bool if the current Span indicates an “unknown” position.
Example
let unknown_span = Span::unknown();
let known_span = Span::new(4, 6);
assert_eq!(unknown_span.is_unknown(), true);
assert_eq!(known_span.is_unknown(), false);
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
sourceimpl PartialOrd<usize> for Span
impl PartialOrd<usize> for Span
sourcefn partial_cmp(&self, other: &usize) -> Option<Ordering>
fn partial_cmp(&self, other: &usize) -> 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
sourceimpl PrettyDebugWithSource for Span
impl PrettyDebugWithSource for Span
fn pretty_debug(&self, source: &str) -> DebugDocBuilder
fn refined_pretty_debug(
&self,
_refine: PrettyDebugRefineKind,
source: &str
) -> DebugDocBuilder
fn debug(&self, source: impl Into<Text>) -> String where
Self: Clone,
fn debuggable(self, source: impl Into<Text>) -> DebuggableWithSource<Self>
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