SpannedStr

Struct SpannedStr 

Source
pub struct SpannedStr<'a, T> { /* private fields */ }
Expand description

The immutable, borrowed equivalent of SpannedString.

Implementations§

Source§

impl<'a, T> SpannedStr<'a, T>
where T: 'a,

Source

pub const fn new(source: &'a str, spans: &'a [IndexedSpan<T>]) -> Self

Creates a new SpannedStr from the given references.

Source

pub const fn empty() -> Self

Creates a new empty SpannedStr.

Source

pub fn spans<'b>( &'b self, ) -> impl DoubleEndedIterator<Item = Span<'a, T>> + ExactSizeIterator<Item = Span<'a, T>> + 'b
where 'a: 'b,

Gives access to the parsed styled spans.

Source

pub const fn spans_raw(&self) -> &'a [IndexedSpan<T>]

Returns a reference to the indexed spans.

Source

pub const fn source(&self) -> &'a str

Returns a reference to the source (non-parsed) string.

Source

pub const fn is_empty(&self) -> bool

Returns true if self is empty.

Can be caused by an empty source, or no span.

Source

pub fn width(&self) -> usize

Returns the width taken by this string.

This is the sum of the width of each span.

Source

pub fn from_spanned_text<'b, S>(text: &'b S) -> Self
where S: SpannedText<S = IndexedSpan<T>>, 'b: 'a,

Create a new SpannedStr by borrowing from a SpannedText.

Trait Implementations§

Source§

impl<'a, T> Clone for SpannedStr<'a, T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a, T: Debug> Debug for SpannedStr<'a, T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a, T> From<&'a SpannedString<T>> for SpannedStr<'a, T>

Source§

fn from(other: &'a SpannedString<T>) -> Self

Converts to this type from the input type.
Source§

impl<'a, T: Hash> Hash for SpannedStr<'a, T>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<'a, T: PartialEq> PartialEq for SpannedStr<'a, T>

Source§

fn eq(&self, other: &SpannedStr<'a, T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a, T> SpannedText for SpannedStr<'a, T>
where T: 'a,

Source§

type S = IndexedSpan<T>

Type of span returned by SpannedText::spans(). Read more
Source§

fn source(&self) -> &str

Returns the source text.
Source§

fn spans(&self) -> &[IndexedSpan<T>]

Returns the spans for this text.
Source§

fn as_ref(&self) -> SpannedTextRef<'_, Self>

Returns a SpannedText by reference.
Source§

impl<'a, T: Eq> Eq for SpannedStr<'a, T>

Source§

impl<'a, T> StructuralPartialEq for SpannedStr<'a, T>

Auto Trait Implementations§

§

impl<'a, T> Freeze for SpannedStr<'a, T>

§

impl<'a, T> RefUnwindSafe for SpannedStr<'a, T>
where T: RefUnwindSafe,

§

impl<'a, T> Send for SpannedStr<'a, T>
where T: Sync,

§

impl<'a, T> Sync for SpannedStr<'a, T>
where T: Sync,

§

impl<'a, T> Unpin for SpannedStr<'a, T>

§

impl<'a, T> UnwindSafe for SpannedStr<'a, T>
where T: RefUnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> With for T

Source§

fn wrap_with<U, F: FnOnce(Self) -> U>(self, f: F) -> U

Calls the given closure and return the result. Read more
Source§

fn with<F: FnOnce(&mut Self)>(self, f: F) -> Self

Calls the given closure on self.
Source§

fn try_with<E, F>(self, f: F) -> Result<Self, E>
where F: FnOnce(&mut Self) -> Result<(), E>,

Calls the given closure on self.
Source§

fn with_if<F>(self, condition: bool, f: F) -> Self
where F: FnOnce(&mut Self),

Calls the given closure if condition == true.