Struct TokenStream

Source
pub struct TokenStream<T: Token>(/* private fields */);
Expand description

A stream of tokens. Tokens in this case are either PreTokens or PostTokens. Note that, unless you are working on formatting specifically, you should never need to work with PostTokens.

Implementations§

Source§

impl TokenStream<PreToken>

Source

pub fn blank_line(&mut self)

Inserts a blank line token to the stream if the stream does not already end with a blank line. This will replace any Trivia::BlankLine tokens with PreToken::BlankLine.

Source

pub fn end_line(&mut self)

Inserts an end of line token to the stream if the stream does not already end with an end of line token.

This will also trim any trailing PreToken::WordEnd tokens.

Source

pub fn end_word(&mut self)

Inserts a word end token to the stream if the stream does not already end with a word end token.

Source

pub fn increment_indent(&mut self)

Inserts an indent start token to the stream. This will also end the current line.

Source

pub fn decrement_indent(&mut self)

Inserts an indent end token to the stream. This will also end the current line.

Source

pub fn allow_blank_lines(&mut self)

Inserts a trivial blank lines “always allowed” context change.

Source

pub fn ignore_trailing_blank_lines(&mut self)

Inserts a trivial blank lines “not allowed after comments” context change.

Source

pub fn push_ast_token(&mut self, token: &Token)

Pushes an AST token into the stream.

This will also push any preceding or inline trivia into the stream. Any token may have preceding or inline trivia, unless that token is itself trivia (i.e. trivia cannot have trivia).

§Panics

This will panic if the provided token is trivia.

Source

pub fn push_literal_in_place_of_token( &mut self, token: &Token, replacement: String, )

Pushes a literal string into the stream in place of an AST token.

This will insert any trivia that would have been inserted with the AST token.

§Panics

This will panic if the provided token is trivia.

Source

pub fn push_literal(&mut self, value: String, kind: SyntaxKind)

Pushes a literal string into the stream.

This will not insert any trivia.

Source

pub fn last_literal_kind(&self) -> Option<SyntaxKind>

Returns the kind of the last literal token in the stream.

Source§

impl<T: Token> TokenStream<T>

Source

pub fn push(&mut self, token: T)

Pushes a token into the stream.

Source

pub fn trim_end(&mut self, token: &T)

Removes any number of tokens at the end of the stream.

Source

pub fn trim_while<F: Fn(&T) -> bool>(&mut self, predicate: F)

Removes any number of tokens at the end of the stream.

Source

pub fn is_empty(&self) -> bool

Returns whether the stream is empty.

Source

pub fn iter(&self) -> Iter<'_, T>

Returns an iterator over the tokens in the stream.

Source

pub fn clear(&mut self)

Clears the stream.

Source

pub fn extend(&mut self, other: Self)

Extends the stream with the tokens from another stream.

Trait Implementations§

Source§

impl<T: Clone + Token> Clone for TokenStream<T>

Source§

fn clone(&self) -> TokenStream<T>

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<T: Debug + Token> Debug for TokenStream<T>

Source§

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

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

impl<T: Token> Default for TokenStream<T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<T: Token> IntoIterator for TokenStream<T>

Source§

type IntoIter = IntoIter<<TokenStream<T> as IntoIterator>::Item>

Which kind of iterator are we turning this into?
Source§

type Item = T

The type of the elements being iterated over.
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

§

impl<T> Freeze for TokenStream<T>

§

impl<T> RefUnwindSafe for TokenStream<T>
where T: RefUnwindSafe,

§

impl<T> Send for TokenStream<T>
where T: Send,

§

impl<T> Sync for TokenStream<T>
where T: Sync,

§

impl<T> Unpin for TokenStream<T>
where T: Unpin,

§

impl<T> UnwindSafe for TokenStream<T>
where T: UnwindSafe,

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<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> ErasedDestructor for T
where T: 'static,