Struct cstree::SyntaxText[][src]

pub struct SyntaxText<'n, 'i, I: ?Sized, L: Language, D: 'static = (), R: 'static = ()> { /* fields omitted */ }

An efficient representation of the text that is covered by a SyntaxNode, i.e. the combined source text of all tokens that are descendants of the node.

Offers methods to work with the text distributed across multiple SyntaxTokens while avoiding the construction of intermediate strings where possible. This includes efficient comparisons with itself and with strings and conversion to_string().

Example

let node = parse_float_literal("2.748E2");
let text = node.text();
assert_eq!(text.len(), 7.into());
assert!(text.contains_char('E'));
assert_eq!(text.find_char('E'), Some(5.into()));
assert_eq!(text.char_at(1.into()), Some('.'));
let sub = text.slice(2.into()..5.into());
assert_eq!(sub, "748");

Implementations

impl<'n, 'i, I: Resolver + ?Sized, L: Language, D, R> SyntaxText<'n, 'i, I, L, D, R>[src]

pub fn len(&self) -> TextSize[src]

The combined length of this text, in bytes.

pub fn is_empty(&self) -> bool[src]

Returns true if self.len() is zero.

pub fn contains_char(&self, c: char) -> bool[src]

Returns true if c appears anywhere in this text.

pub fn find_char(&self, c: char) -> Option<TextSize>[src]

If self.contains_char(c), returns Some(pos), where pos is the byte position of the first appearance of c. Otherwise, returns None.

pub fn char_at(&self, offset: TextSize) -> Option<char>[src]

If offset < self.len(), returns Some(c), where c is the first char at or after offset (in bytes). Otherwise, returns None.

pub fn slice<Ra: SyntaxTextRange>(&self, range: Ra) -> Self[src]

Indexes this text by the given range and returns a SyntaxText that represents the corresponding slice of this text.

Panics

The end of range must be equal of higher than its start. Further, range must be contained within 0..self.len().

pub fn try_fold_chunks<T, F, E>(&self, init: T, f: F) -> Result<T, E> where
    F: FnMut(T, &str) -> Result<T, E>, 
[src]

Applies the given function to text chunks (from SyntaxTokens) that are part of this text as long as it returns Ok, starting from the initial value init.

If f returns Err, the error is propagated immediately. Otherwise, the result of the current call to f will be passed to the invocation of f on the next token, producing a final value if f succeeds on all chunks.

pub fn try_for_each_chunk<F: FnMut(&str) -> Result<(), E>, E>(
    &self,
    f: F
) -> Result<(), E>
[src]

Applies the given function to all text chunks that this text is comprised of, in order, as long as f completes successfully.

If f returns Err, this method returns immediately and will not apply f to any further chunks.

See also try_fold_chunks.

pub fn for_each_chunk<F: FnMut(&str)>(&self, f: F)[src]

Applies the given function to all text chunks that this text is comprised of, in order.

See also try_fold_chunks, try_for_each_chunk.

Trait Implementations

impl<'n, 'i, I: Clone + ?Sized, L: Clone + Language, D: Clone + 'static, R: Clone + 'static> Clone for SyntaxText<'n, 'i, I, L, D, R>[src]

impl<I: Resolver + ?Sized, L: Language, D, R> Debug for SyntaxText<'_, '_, I, L, D, R>[src]

impl<I: Resolver + ?Sized, L: Language, D, R> Display for SyntaxText<'_, '_, I, L, D, R>[src]

impl<I: Resolver + ?Sized, L: Language, D> Eq for SyntaxText<'_, '_, I, L, D>[src]

impl<I: Resolver + ?Sized, L: Language, D, R> PartialEq<&'_ str> for SyntaxText<'_, '_, I, L, D, R>[src]

impl<'n1, 'i1, 'n2, 'i2, I1: ?Sized, I2: ?Sized, L1, L2, D1, D2, R1, R2> PartialEq<SyntaxText<'n2, 'i2, I2, L2, D2, R2>> for SyntaxText<'n1, 'i1, I1, L1, D1, R1> where
    L1: Language,
    L2: Language,
    I1: Resolver,
    I2: Resolver
[src]

impl<I: Resolver + ?Sized, L: Language, D, R> PartialEq<str> for SyntaxText<'_, '_, I, L, D, R>[src]

Auto Trait Implementations

impl<'n, 'i, I, L, D = (), R = ()> !RefUnwindSafe for SyntaxText<'n, 'i, I, L, D, R>

impl<'n, 'i, I: ?Sized, L, D, R> Send for SyntaxText<'n, 'i, I, L, D, R> where
    I: Sync

impl<'n, 'i, I: ?Sized, L, D, R> Sync for SyntaxText<'n, 'i, I, L, D, R> where
    I: Sync

impl<'n, 'i, I: ?Sized, L, D, R> Unpin for SyntaxText<'n, 'i, I, L, D, R>

impl<'n, 'i, I, L, D = (), R = ()> !UnwindSafe for SyntaxText<'n, 'i, I, L, D, R>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.