[−][src]Struct nu_source::Span
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
impl Span
[src]
pub fn default() -> Self
[src]
Creates a default new Span
that has 0 start and 0 end.
pub fn unknown() -> Span
[src]
Creates a new Span
that has 0 start and 0 end.
pub fn new(start: usize, end: usize) -> Span
[src]
Creates a new Span
from start and end inputs. The end parameter must be greater than or equal to the start parameter.
pub fn for_char(pos: usize) -> Span
[src]
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);
pub fn contains(&self, pos: usize) -> bool
[src]
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);
pub fn since(&self, other: impl Into<Span>) -> Span
[src]
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);
pub fn until(&self, other: impl Into<Span>) -> Span
[src]
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 until_option(&self, other: Option<impl Into<Span>>) -> Span
[src]
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
[src]
pub fn spanned_slice<'a>(&self, source: &'a str) -> Spanned<&'a str>
[src]
pub fn spanned_string(&self, source: &str) -> Spanned<String>
[src]
pub fn start(&self) -> usize
[src]
Returns the start position of the current Span.
pub fn end(&self) -> usize
[src]
Returns the end position of the current Span.
pub fn is_unknown(&self) -> bool
[src]
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);
pub fn is_closed(&self) -> bool
[src]
Returns a bool if the current Span does not cover.
Example
// make clean // ---- // (0,4) // // ^(5,5) let make_span = Span::new(0,4); let clean_span = Span::new(5,5); assert_eq!(make_span.is_closed(), false); assert_eq!(clean_span.is_closed(), true);
pub fn slice<'a>(&self, source: &'a str) -> &'a str
[src]
Returns a slice of the input that covers the start and end of the current Span.
Trait Implementations
impl Clone for Span
[src]
impl Copy for Span
[src]
impl Debug for Span
[src]
impl Default for Span
[src]
impl<'de> Deserialize<'de> for Span
[src]
pub fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
[src]
__D: Deserializer<'de>,
impl Eq for Span
[src]
impl From<&'_ Range<usize>> for Span
[src]
impl From<&'_ Span> for Tag
[src]
impl From<&'_ Span> for Span
[src]
impl From<&'_ Tag> for Span
[src]
impl From<(usize, usize)> for Span
[src]
impl From<Option<Span>> for Span
[src]
impl From<Span> for Tag
[src]
impl From<Span> for Range<usize>
[src]
impl From<Tag> for Span
[src]
impl HasSpan for Span
[src]
impl Hash for Span
[src]
pub fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
pub fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl Ord for Span
[src]
pub fn cmp(&self, other: &Span) -> Ordering
[src]
#[must_use]pub fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn clamp(self, min: Self, max: Self) -> Self
1.50.0[src]
impl PartialEq<Span> for Span
[src]
impl PartialEq<usize> for Span
[src]
pub fn eq(&self, other: &usize) -> bool
[src]
#[must_use]pub fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl PartialOrd<Span> for Span
[src]
pub fn partial_cmp(&self, other: &Span) -> Option<Ordering>
[src]
pub fn lt(&self, other: &Span) -> bool
[src]
pub fn le(&self, other: &Span) -> bool
[src]
pub fn gt(&self, other: &Span) -> bool
[src]
pub fn ge(&self, other: &Span) -> bool
[src]
impl PartialOrd<usize> for Span
[src]
pub fn partial_cmp(&self, other: &usize) -> Option<Ordering>
[src]
#[must_use]pub fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
impl PrettyDebugWithSource for Span
[src]
pub fn pretty_debug(&self, source: &str) -> DebugDocBuilder
[src]
pub fn refined_pretty_debug(
&self,
_refine: PrettyDebugRefineKind,
source: &str
) -> DebugDocBuilder
[src]
&self,
_refine: PrettyDebugRefineKind,
source: &str
) -> DebugDocBuilder
pub fn debug(&self, source: impl Into<Text>) -> String where
Self: Clone,
[src]
Self: Clone,
pub fn debuggable(self, source: impl Into<Text>) -> DebuggableWithSource<Self>
[src]
impl Serialize for Span
[src]
pub fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error> where
__S: Serializer,
[src]
__S: Serializer,
impl StructuralEq for Span
[src]
impl StructuralPartialEq for Span
[src]
Auto Trait Implementations
impl RefUnwindSafe for Span
[src]
impl Send for Span
[src]
impl Sync for Span
[src]
impl Unpin for Span
[src]
impl UnwindSafe for Span
[src]
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,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> DeserializeOwned for T where
T: for<'de> Deserialize<'de>,
[src]
T: for<'de> Deserialize<'de>,
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,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,