pub enum FormatElement {
    Space,
    HardSpace,
    Line(LineMode),
    ExpandParent,
    StaticText {
        text: &'static str,
    },
    DynamicText {
        text: Box<str>,
        source_position: TextSize,
    },
    LocatedTokenText {
        source_position: TextSize,
        slice: TokenText,
    },
    LineSuffixBoundary,
    Interned(Interned),
    BestFitting(BestFittingElement),
    Tag(Tag),
}
Expand description

Language agnostic IR for formatting source code.

Use the helper functions like crate::builders::space, crate::builders::soft_line_break etc. defined in this file to create elements.

Variants§

§

Space

A space token, see crate::builders::space for documentation.

§

HardSpace

§

Line(LineMode)

§

ExpandParent

Forces the parent group to print in expanded mode.

§

StaticText

Fields

§text: &'static str

Token constructed by the formatter from a static string

§

DynamicText

Fields

§text: Box<str>

There’s no need for the text to be mutable, using Box<str> safes 8 bytes over String.

§source_position: TextSize

The start position of the dynamic token in the unformatted source code

Token constructed from the input source as a dynamic string with its start position in the input document.

§

LocatedTokenText

Fields

§source_position: TextSize

The start position of the token in the unformatted source code

§slice: TokenText

The token text

A token for a text that is taken as is from the source code (input text and formatted representation are identical). Implementing by taking a slice from a SyntaxToken to avoid allocating a new string.

§

LineSuffixBoundary

Prevents that line suffixes move past this boundary. Forces the printer to print any pending line suffixes, potentially by inserting a hard line break.

§

Interned(Interned)

An interned format element. Useful when the same content must be emitted multiple times to avoid deep cloning the IR when using the best_fitting! macro or if_group_fits_on_line and if_group_breaks.

§

BestFitting(BestFittingElement)

A list of different variants representing the same content. The printer picks the best fitting content. Line breaks inside of a best fitting don’t propagate to parent groups.

§

Tag(Tag)

A Tag that marks the start/end of some content to which some special formatting is applied.

Implementations§

source§

impl FormatElement

source

pub const fn is_tag(&self) -> bool

Returns true if self is a FormatElement::Tag

source

pub const fn is_start_tag(&self) -> bool

Returns true if self is a FormatElement::Tag and Tag::is_start is true.

source

pub const fn is_end_tag(&self) -> bool

Returns true if self is a FormatElement::Tag and Tag::is_end is true.

source

pub const fn is_text(&self) -> bool

source

pub const fn is_space(&self) -> bool

source

pub const fn is_line(&self) -> bool

Trait Implementations§

source§

impl Clone for FormatElement

source§

fn clone(&self) -> FormatElement

Returns a copy 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 Debug for FormatElement

source§

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

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

impl FormatElements for FormatElement

source§

fn will_break(&self) -> bool

Returns true if this FormatElement is guaranteed to break across multiple lines by the printer. This is the case if this format element recursively contains a: Read more
source§

fn may_directly_break(&self) -> bool

Returns true if this FormatElement has the potential to break across multiple lines when printed. This is the case only if this format element recursively contains a FormatElement::Line. Read more
source§

fn has_label(&self, label_id: LabelId) -> bool

Returns true if the element has the given label.
source§

fn start_tag(&self, _: TagKind) -> Option<&Tag>

Returns the start tag of kind if: Read more
source§

fn end_tag(&self, kind: TagKind) -> Option<&Tag>

Returns the end tag if: Read more
source§

impl PartialEq for FormatElement

source§

fn eq(&self, other: &FormatElement) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Eq for FormatElement

source§

impl StructuralPartialEq for FormatElement

Auto Trait Implementations§

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> DynClone for T
where T: Clone,

source§

fn __clone_box(&self, _: Private) -> *mut ()

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<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> 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> ToOwned for T
where T: Clone,

§

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

§

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