pub struct FormatState<Context> {
    pub printed_tokens: PrintedTokens,
    /* private fields */
}
Expand description

This structure stores the state that is relevant for the formatting of the whole document.

This structure is different from crate::Formatter in that the formatting infrastructure creates a new crate::Formatter for every crate::write! call, whereas this structure stays alive for the whole process of formatting a root with crate::format!.

Fields§

§printed_tokens: PrintedTokens

Implementations§

source§

impl<Context> FormatState<Context>

source

pub fn new(context: Context) -> Self

Creates a new state with the given language specific context

source

pub fn into_context(self) -> Context

source

pub fn context(&self) -> &Context

Returns the context specifying how to format the current CST

source

pub fn context_mut(&mut self) -> &mut Context

Returns a mutable reference to the context

source

pub fn group_id(&self, debug_name: &'static str) -> GroupId

Creates a new group id that is unique to this document. The passed debug name is used in the std::fmt::Debug of the document if this is a debug build. The name is unused for production builds and has no meaning on the equality of two group ids.

source

pub fn track_token<L: Language>(&mut self, token: &SyntaxToken<L>)

Tracks the given token as formatted

source

pub fn set_token_tracking_disabled(&mut self, enabled: bool)

Disables or enables token tracking for a portion of the code.

It can be useful to disable the token tracking when it is necessary to re-format a node with different parameters.

source

pub fn is_token_tracking_disabled(&self) -> bool

Returns true if token tracking is currently disabled.

source

pub fn assert_formatted_all_tokens<L: Language>(&self, root: &SyntaxNode<L>)

Asserts in debug builds that all tokens have been printed.

source§

impl<Context> FormatState<Context>
where Context: FormatContext,

Trait Implementations§

source§

impl<Context> Debug for FormatState<Context>
where Context: Debug,

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<Context> !Freeze for FormatState<Context>

§

impl<Context> RefUnwindSafe for FormatState<Context>
where Context: RefUnwindSafe,

§

impl<Context> Send for FormatState<Context>
where Context: Send,

§

impl<Context> Sync for FormatState<Context>
where Context: Sync,

§

impl<Context> Unpin for FormatState<Context>
where Context: Unpin,

§

impl<Context> UnwindSafe for FormatState<Context>
where Context: 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> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more