pub(crate) struct FixupContext {
previous_operator: Precedence,
next_operator: Precedence,
stmt: bool,
leftmost_subexpression_in_stmt: bool,
match_arm: bool,
leftmost_subexpression_in_match_arm: bool,
condition: bool,
rightmost_subexpression_in_condition: bool,
leftmost_subexpression_in_optional_operand: bool,
next_operator_can_begin_expr: bool,
next_operator_can_continue_expr: bool,
next_operator_can_begin_generics: bool,
}
Fields§
§previous_operator: Precedence
§next_operator: Precedence
§stmt: bool
§leftmost_subexpression_in_stmt: bool
§match_arm: bool
§leftmost_subexpression_in_match_arm: bool
§condition: bool
§rightmost_subexpression_in_condition: bool
§leftmost_subexpression_in_optional_operand: bool
§next_operator_can_begin_expr: bool
§next_operator_can_continue_expr: bool
§next_operator_can_begin_generics: bool
Implementations§
source§impl FixupContext
impl FixupContext
sourcepub const NONE: Self = _
pub const NONE: Self = _
The default amount of fixing is minimal fixing. Fixups should be turned on in a targeted fashion where needed.
sourcepub fn new_stmt() -> Self
pub fn new_stmt() -> Self
Create the initial fixup for printing an expression in statement position.
sourcepub fn new_match_arm() -> Self
pub fn new_match_arm() -> Self
Create the initial fixup for printing an expression as the right-hand side of a match arm.
sourcepub fn new_condition() -> Self
pub fn new_condition() -> Self
Create the initial fixup for printing an expression as the “condition”
of an if
or while
. There are a few other positions which are
grammatically equivalent and also use this, such as the iterator
expression in for
and the scrutinee in match
.
sourcepub fn leftmost_subexpression_with_operator(
self,
expr: &Expr,
next_operator_can_begin_expr: bool,
next_operator_can_begin_generics: bool,
precedence: Precedence,
) -> (Precedence, Self)
pub fn leftmost_subexpression_with_operator( self, expr: &Expr, next_operator_can_begin_expr: bool, next_operator_can_begin_generics: bool, precedence: Precedence, ) -> (Precedence, Self)
Transform this fixup into the one that should apply when printing the leftmost subexpression of the current expression.
The leftmost subexpression is any subexpression that has the same first token as the current expression, but has a different last token.
For example in $a + $b
and $a.method()
, the subexpression $a
is a
leftmost subexpression.
Not every expression has a leftmost subexpression. For example neither
-$a
nor [$a]
have one.
sourcepub fn leftmost_subexpression_with_dot(self, expr: &Expr) -> (Precedence, Self)
pub fn leftmost_subexpression_with_dot(self, expr: &Expr) -> (Precedence, Self)
Transform this fixup into the one that should apply when printing a
leftmost subexpression followed by a .
or ?
token, which confer
different statement boundary rules compared to other leftmost
subexpressions.
fn leftmost_subexpression_precedence(self, expr: &Expr) -> Precedence
sourcepub fn rightmost_subexpression(
self,
expr: &Expr,
precedence: Precedence,
) -> (Precedence, Self)
pub fn rightmost_subexpression( self, expr: &Expr, precedence: Precedence, ) -> (Precedence, Self)
Transform this fixup into the one that should apply when printing the rightmost subexpression of the current expression.
The rightmost subexpression is any subexpression that has a different first token than the current expression, but has the same last token.
For example in $a + $b
and -$b
, the subexpression $b
is a
rightmost subexpression.
Not every expression has a rightmost subexpression. For example neither
[$b]
nor $a.f($b)
have one.
pub fn rightmost_subexpression_fixup( self, reset_allow_struct: bool, optional_operand: bool, precedence: Precedence, ) -> Self
pub fn rightmost_subexpression_precedence(self, expr: &Expr) -> Precedence
sourcepub fn parenthesize(self, expr: &Expr) -> bool
pub fn parenthesize(self, expr: &Expr) -> bool
Determine whether parentheses are needed around the given expression to head off the early termination of a statement or condition.
sourcefn precedence(self, expr: &Expr) -> Precedence
fn precedence(self, expr: &Expr) -> Precedence
Determines the effective precedence of a subexpression. Some expressions have higher or lower precedence when adjacent to particular operators.
Trait Implementations§
source§impl Clone for FixupContext
impl Clone for FixupContext
impl Copy for FixupContext
Auto Trait Implementations§
impl Freeze for FixupContext
impl RefUnwindSafe for FixupContext
impl Send for FixupContext
impl Sync for FixupContext
impl Unpin for FixupContext
impl UnwindSafe for FixupContext
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§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)