syn::fixup

Struct FixupContext

source
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

source

pub const NONE: Self = _

The default amount of fixing is minimal fixing. Fixups should be turned on in a targeted fashion where needed.

source

pub fn new_stmt() -> Self

Create the initial fixup for printing an expression in statement position.

source

pub fn new_match_arm() -> Self

Create the initial fixup for printing an expression as the right-hand side of a match arm.

source

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.

source

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.

source

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.

source

fn leftmost_subexpression_precedence(self, expr: &Expr) -> Precedence

source

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.

source

pub fn rightmost_subexpression_fixup( self, reset_allow_struct: bool, optional_operand: bool, precedence: Precedence, ) -> Self

source

pub fn rightmost_subexpression_precedence(self, expr: &Expr) -> Precedence

source

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.

source

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

source§

fn clone(&self) -> Self

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 Copy for FixupContext

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, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

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,

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.