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)
A new line, see crate::builders::soft_line_break, crate::builders::hard_line_break, and crate::builders::soft_line_break_or_space for documentation.
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.
Text
An arbitrary text that can contain tabs, newlines, and unicode characters.
Fields
SourceCodeSlice
Text that gets emitted as it is in the source code. Optimized to avoid any allocations.
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
impl FormatElement
Sourcepub const fn is_tag(&self) -> bool
pub const fn is_tag(&self) -> bool
Returns true if self is a FormatElement::Tag
Sourcepub const fn is_start_tag(&self) -> bool
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
impl Clone for FormatElement
Source§fn clone(&self) -> FormatElement
fn clone(&self) -> FormatElement
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for FormatElement
impl Debug for FormatElement
impl Eq for FormatElement
Source§impl FormatElements for FormatElement
impl FormatElements for FormatElement
Source§fn will_break(&self) -> bool
fn will_break(&self) -> bool
FormatElement is guaranteed to break across multiple lines by the printer.
This is the case if this format element recursively contains a: Read moreSource§impl PartialEq for FormatElement
impl PartialEq for FormatElement
impl StructuralPartialEq for FormatElement
Auto Trait Implementations§
impl !Freeze for FormatElement
impl !RefUnwindSafe for FormatElement
impl !Send for FormatElement
impl !Sync for FormatElement
impl !UnwindSafe for FormatElement
impl Unpin for FormatElement
impl UnsafeUnpin for FormatElement
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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