Skip to main content

FormatElement

Enum FormatElement 

Source
pub enum FormatElement {
    Space,
    Line(LineMode),
    ExpandParent,
    SourcePosition(TextSize),
    Token {
        text: &'static str,
    },
    Text {
        text: Box<str>,
        text_width: TextWidth,
    },
    SourceCodeSlice {
        slice: SourceCodeSlice,
        text_width: TextWidth,
    },
    LineSuffixBoundary,
    Interned(Interned),
    BestFitting {
        variants: BestFittingVariants,
        mode: BestFittingMode,
    },
    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.

§

Line(LineMode)

§

ExpandParent

Forces the parent group to print in expanded mode.

§

SourcePosition(TextSize)

Indicates the position of the elements coming after this element in the source document. The printer will create a source map entry from this position in the source document to the formatted position.

§

Token

A ASCII only Token that contains no line breaks or tab characters.

Fields

§text: &'static str
§

Text

An arbitrary text that can contain tabs, newlines, and unicode characters.

Fields

§text: Box<str>

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

§text_width: TextWidth
§

SourceCodeSlice

Text that gets emitted as it is in the source code. Optimized to avoid any allocations.

Fields

§text_width: TextWidth
§

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

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.

Trait Implementations§

Source§

impl Clone for FormatElement

Source§

fn clone(&self) -> FormatElement

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · 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 Eq for FormatElement

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
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> 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> 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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> 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