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)
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.
StaticText
Token constructed by the formatter from a static string
DynamicText
Fields
Token constructed from the input source as a dynamic string with its start position in the input document.
LocatedTokenText
Fields
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
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
.
sourcepub const fn is_end_tag(&self) -> bool
pub const fn is_end_tag(&self) -> bool
Returns true
if self is a FormatElement::Tag and Tag::is_end is true
.
pub const fn is_text(&self) -> bool
pub const fn is_space(&self) -> bool
pub const fn is_line(&self) -> bool
Trait Implementations§
source§impl Clone for FormatElement
impl Clone for FormatElement
source§fn clone(&self) -> FormatElement
fn clone(&self) -> FormatElement
1.0.0 · 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
source§impl FormatElements for FormatElement
impl FormatElements for FormatElement
source§fn will_break(&self) -> bool
fn will_break(&self) -> bool
source§fn may_directly_break(&self) -> bool
fn may_directly_break(&self) -> bool
source§impl PartialEq for FormatElement
impl PartialEq for FormatElement
source§fn eq(&self, other: &FormatElement) -> bool
fn eq(&self, other: &FormatElement) -> bool
self
and other
values to be equal, and is used
by ==
.impl Eq 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 Unpin for FormatElement
impl !UnwindSafe 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<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.