## State

# Struct State

Source

    pub struct State<'a> {
        pub s: Printer,
        comments: Option<Comments<'a>>,
        ann: &'a (dyn PpAnn + 'a),
        is_sdylib_interface: bool,
    }

## Fields§

§`s: Printer`§`comments: Option<Comments<'a>>`§`ann: &'a (dyn PpAnn + 'a)`§`is_sdylib_interface: bool`

## Implementations§

Source§

### impl<'a> State<'a>

Source

#### fn print_else(&mut self, els: Option<&Expr>)

Source

#### fn print_if(&mut self, test: &Expr, blk: &Block, elseopt: Option<&Expr>)

Source

#### fn print_call_post(&mut self, args: &[Box<Expr>])

Source

#### fn print_expr_as_cond(&mut self, expr: &Expr)

Prints an expr using syntax that’s acceptable in a condition position, such as the `cond` in `if cond { ... }`.

Source

#### fn cond_needs_par(expr: &Expr) -> bool

Does `expr` need parentheses when printed in a condition position?

These cases need parens due to the parse error observed in #26461: `if return {}` parses as the erroneous construct `if (return {})`, not `if (return) {}`.

Source

#### pub(super) fn print_expr_cond_paren( &mut self, expr: &Expr, needs_par: bool, fixup: FixupContext, )

Prints `expr` or `(expr)` when `needs_par` holds.

Source

#### fn print_expr_vec(&mut self, exprs: &[Box<Expr>])

Source

#### pub(super) fn print_expr_anon_const( &mut self, expr: &AnonConst, attrs: &[Attribute], )

Source

#### fn print_expr_repeat(&mut self, element: &Expr, count: &AnonConst)

Source

#### fn print_expr_struct( &mut self, qself: &Option<Box<QSelf>>, path: &Path, fields: &[ExprField], rest: &StructRest, )

Source

#### fn print_expr_tup(&mut self, exprs: &[Box<Expr>])

Source

#### fn print_expr_call( &mut self, func: &Expr, args: &[Box<Expr>], fixup: FixupContext, )

Source

#### fn print_expr_method_call( &mut self, segment: &PathSegment, receiver: &Expr, base_args: &[Box<Expr>], fixup: FixupContext, )

Source

#### fn print_expr_binary( &mut self, op: BinOpKind, lhs: &Expr, rhs: &Expr, fixup: FixupContext, )

Source

#### fn print_expr_unary(&mut self, op: UnOp, expr: &Expr, fixup: FixupContext)

Source

#### fn print_expr_addr_of( &mut self, kind: BorrowKind, mutability: Mutability, expr: &Expr, fixup: FixupContext, )

Source

#### pub(super) fn print_expr(&mut self, expr: &Expr, fixup: FixupContext)

Source

#### pub(super) fn print_expr_outer_attr_style( &mut self, expr: &Expr, is_inline: bool, fixup: FixupContext, )

Source

#### fn print_arm(&mut self, arm: &Arm)

Source

#### fn print_closure_binder(&mut self, binder: &ClosureBinder)

Source

#### fn print_movability(&mut self, movability: Movability)

Source

#### fn print_capture_clause(&mut self, capture_clause: CaptureBy)

Source§

### impl<'a> State<'a>

Source

#### fn print_foreign_mod(&mut self, nmod: &ForeignMod, attrs: &[Attribute])

Source

#### pub(crate) fn print_foreign_item(&mut self, item: &ForeignItem)

Source

#### fn print_item_const( &mut self, ident: Ident, mutbl: Option<Mutability>, generics: &Generics, ty: &Ty, body: Option<&Expr>, vis: &Visibility, safety: Safety, defaultness: Defaultness, define_opaque: Option<&[(NodeId, Path)]>, )

Source

#### fn print_associated_type( &mut self, ident: Ident, generics: &Generics, after_where_clause: &WhereClause, bounds: &GenericBounds, ty: Option<&Ty>, vis: &Visibility, defaultness: Defaultness, )

Source

#### pub(crate) fn print_item(&mut self, item: &Item)

Pretty-prints an item.

Source

#### fn print_enum_def( &mut self, enum_definition: &EnumDef, generics: &Generics, ident: Ident, span: Span, visibility: &Visibility, )

Source

#### pub(crate) fn print_visibility(&mut self, vis: &Visibility)

Source

#### fn print_defaultness(&mut self, defaultness: Defaultness)

Source

#### fn print_struct( &mut self, struct_def: &VariantData, generics: &Generics, ident: Ident, span: Span, print_finalizer: bool, cb: BoxMarker, ib: BoxMarker, )

Source

#### pub(crate) fn print_variant(&mut self, v: &Variant)

Source

#### pub(crate) fn print_assoc_item(&mut self, item: &AssocItem)

Source

#### fn print_delegation( &mut self, attrs: &[Attribute], vis: &Visibility, qself: &Option<Box<QSelf>>, path: &Path, kind: DelegationKind<'_>, body: &Option<Box<Block>>, )

Source

#### fn print_fn_full(&mut self, vis: &Visibility, attrs: &[Attribute], func: &Fn)

Source

#### fn print_define_opaques(&mut self, define_opaque: Option<&[(NodeId, Path)]>)

Source

#### fn print_contract(&mut self, contract: &FnContract)

Source

#### pub(crate) fn print_fn( &mut self, decl: &FnDecl, header: FnHeader, ident: Option<Ident>, generics: &Generics, )

Source

#### pub(crate) fn print_fn_params_and_ret( &mut self, decl: &FnDecl, is_closure: bool, )

Source

#### fn print_where_clause(&mut self, where_clause: &WhereClause)

Source

#### pub fn print_where_predicate(&mut self, predicate: &WherePredicate)

Source

#### pub(crate) fn print_where_bound_predicate( &mut self, where_bound_predicate: &WhereBoundPredicate, )

Source

#### fn print_use_tree(&mut self, tree: &UseTree)

Source§

### impl<'a> State<'a>

Source

#### pub fn new() -> State<'a>

Source

#### fn commasep_cmnt<T, F, G>(&mut self, b: Breaks, elts: &[T], op: F, get_span: G)
where F: FnMut(&mut State<'_>, &T), G: FnMut(&T) -> Span,

Source

#### fn commasep_exprs(&mut self, b: Breaks, exprs: &[Box<Expr>])

Source

#### pub fn print_opt_lifetime(&mut self, lifetime: &Option<Lifetime>)

Source

#### pub fn print_assoc_item_constraint(&mut self, constraint: &AssocItemConstraint)

Source

#### pub fn print_generic_arg(&mut self, generic_arg: &GenericArg)

Source

#### pub fn print_ty_pat(&mut self, pat: &TyPat)

Source

#### pub fn print_type(&mut self, ty: &Ty)

Source

#### fn print_trait_ref(&mut self, t: &TraitRef)

Source

#### fn print_formal_generic_params(&mut self, generic_params: &[GenericParam])

Source

#### fn print_poly_trait_ref(&mut self, t: &PolyTraitRef)

Source

#### fn print_stmt(&mut self, st: &Stmt)

Source

#### fn print_block(&mut self, blk: &Block, cb: BoxMarker, ib: BoxMarker)

Source

#### fn print_block_unclosed_indent(&mut self, blk: &Block, ib: BoxMarker)

Source

#### fn print_block_with_attrs( &mut self, blk: &Block, attrs: &[Attribute], cb: BoxMarker, ib: BoxMarker, )

Source

#### fn print_block_maybe_unclosed( &mut self, blk: &Block, attrs: &[Attribute], cb: Option<BoxMarker>, ib: BoxMarker, )

Source

#### fn print_let(&mut self, pat: &Pat, expr: &Expr, fixup: FixupContext)

Print a `let pat = expr` expression.

Parentheses are inserted surrounding `expr` if a round-trip through the parser would otherwise work out the wrong way in a condition position.

For example each of the following would mean the wrong thing without parentheses.

ⓘ

    if let _ = (Struct {}) {}

    if let _ = (true && false) {}

In a match guard, the second case still requires parens, but the first case no longer does because anything until `=>` is considered part of the match guard expression. Parsing of the expression is not terminated by `{` in that position.

ⓘ

    match () {
        () if let _ = Struct {} => {}
        () if let _ = (true && false) => {}
    }

Source

#### fn print_mac(&mut self, m: &MacCall)

Source

#### fn print_inline_asm(&mut self, asm: &InlineAsm)

Source

#### fn print_local_decl(&mut self, loc: &Local)

Source

#### fn print_name(&mut self, name: Symbol)

Source

#### fn print_qpath( &mut self, path: &Path, qself: &QSelf, colons_before_params: bool, )

Source

#### fn print_pat(&mut self, pat: &Pat)

Source

#### fn print_explicit_self(&mut self, explicit_self: &ExplicitSelf)

Source

#### fn print_coroutine_kind(&mut self, coroutine_kind: CoroutineKind)

Source

#### pub fn print_type_bounds(&mut self, bounds: &[GenericBound])

Source

#### fn print_lifetime(&mut self, lifetime: Lifetime)

Source

#### fn print_lifetime_bounds(&mut self, bounds: &GenericBounds)

Source

#### fn print_generic_params(&mut self, generic_params: &[GenericParam])

Source

#### pub fn print_mutability(&mut self, mutbl: Mutability, print_const: bool)

Source

#### fn print_mt(&mut self, mt: &MutTy, print_const: bool)

Source

#### fn print_param(&mut self, input: &Param, is_closure: bool)

Source

#### fn print_fn_ret_ty(&mut self, fn_ret_ty: &FnRetTy)

Source

#### fn print_ty_fn( &mut self, ext: Extern, safety: Safety, decl: &FnDecl, name: Option<Ident>, generic_params: &[GenericParam], )

Source

#### fn print_fn_header_info(&mut self, header: FnHeader)

Source

#### fn print_safety(&mut self, s: Safety)

Source

#### fn print_constness(&mut self, s: Const)

Source

#### fn print_is_auto(&mut self, s: IsAuto)

Source

#### fn print_meta_item_lit(&mut self, lit: &MetaItemLit)

Source

#### fn print_token_literal(&mut self, token_lit: Lit, span: Span)

Source

#### fn print_symbol(&mut self, sym: Symbol, style: StrStyle)

Source

#### fn print_inner_attributes_no_trailing_hardbreak( &mut self, attrs: &[Attribute], ) -> bool

Source

#### fn print_outer_attributes_inline(&mut self, attrs: &[Attribute]) -> bool

Source

#### fn print_attribute(&mut self, attr: &Attribute)

Source

#### fn print_meta_list_item(&mut self, item: &MetaItemInner)

Source

#### fn print_meta_item(&mut self, item: &MetaItem)

Source

#### pub(crate) fn bounds_to_string(&self, bounds: &[GenericBound]) -> String

Source

#### pub(crate) fn where_bound_predicate_to_string( &self, where_bound_predicate: &WhereBoundPredicate, ) -> String

Source

#### pub(crate) fn tt_to_string(&self, tt: &TokenTree) -> String

Source

#### pub(crate) fn path_segment_to_string(&self, p: &PathSegment) -> String

Source

#### pub(crate) fn meta_list_item_to_string(&self, li: &MetaItemInner) -> String

Source

#### pub(crate) fn attribute_to_string(&self, attr: &Attribute) -> String

## Methods from Deref<Target = Printer>§

Source

#### pub fn word_space<W: Into<Cow<'static, str>>>(&mut self, w: W)

Source

#### pub fn popen(&mut self)

Source

#### pub fn pclose(&mut self)

Source

#### pub fn hardbreak_if_not_bol(&mut self)

Source

#### pub fn space_if_not_bol(&mut self)

Source

#### pub fn nbsp(&mut self)

Source

#### pub fn word_nbsp<S: Into<Cow<'static, str>>>(&mut self, w: S)

Source

#### pub fn synth_comment(&mut self, text: impl Into<Cow<'static, str>>)

Synthesizes a comment that was not textually present in the original source file.

Source

#### pub fn rbox(&mut self, indent: isize, breaks: Breaks) -> BoxMarker

“raw box”

Source

#### pub fn ibox(&mut self, indent: isize) -> BoxMarker

Inconsistent breaking box

Source

#### pub fn cbox(&mut self, indent: isize) -> BoxMarker

Consistent breaking box

Source

#### pub fn visual_align(&mut self) -> BoxMarker

Source

#### pub fn break_offset(&mut self, n: usize, off: isize)

Source

#### pub fn end(&mut self, b: BoxMarker)

Source

#### pub fn word<S: Into<Cow<'static, str>>>(&mut self, wrd: S)

Source

#### fn spaces(&mut self, n: usize)

Source

#### pub fn zerobreak(&mut self)

Source

#### pub fn space(&mut self)

Source

#### pub fn hardbreak(&mut self)

Source

#### pub fn is_beginning_of_line(&self) -> bool

Source

#### pub fn trailing_comma(&mut self)

Source

#### pub fn trailing_comma_or_space(&mut self)

Source

#### pub(crate) fn last_token(&self) -> Option<&Token>

Source

#### pub(crate) fn last_token_still_buffered(&self) -> Option<&Token>

Source

#### pub(crate) fn replace_last_token_still_buffered(&mut self, token: Token)

Be very careful with this!

Source

#### fn scan_eof(&mut self)

Source

#### fn scan_begin(&mut self, token: BeginToken) -> BoxMarker

Source

#### fn scan_end(&mut self, b: BoxMarker)

Source

#### fn scan_break(&mut self, token: BreakToken)

Source

#### fn scan_string(&mut self, string: Cow<'static, str>)

Source

#### pub(crate) fn offset(&mut self, offset: isize)

Source

#### fn check_stream(&mut self)

Source

#### fn advance_left(&mut self)

Source

#### fn check_stack(&mut self, depth: usize)

Source

#### fn get_top(&self) -> PrintFrame

Source

#### fn print_begin(&mut self, token: BeginToken, size: isize)

Source

#### fn print_end(&mut self)

Source

#### fn print_break(&mut self, token: BreakToken, size: isize)

Source

#### fn print_string(&mut self, string: &str)

## Trait Implementations§

Source§

### impl Deref for State<'_>

Source§

#### type Target = Printer

The resulting type after dereferencing.
Source§

#### fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

### impl DerefMut for State<'_>

Source§

#### fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

### impl<'a> PrintState<'a> for State<'a>

Source§

#### fn comments(&self) -> Option<&Comments<'a>>

Source§

#### fn comments_mut(&mut self) -> Option<&mut Comments<'a>>

Source§

#### fn ann_post(&mut self, ident: Ident)

Source§

#### fn print_generic_args(&mut self, args: &GenericArgs, colons_before_params: bool)

Source§

#### fn print_ident(&mut self, ident: Ident)

Source§

#### fn strsep<'x, T: 'x, F, I>( &mut self, sep: &'static str, space_before: bool, b: Breaks, elts: I, op: F, )
where F: FnMut(&mut Self, &T), I: IntoIterator<Item = &'x T>,

Source§

#### fn commasep<'x, T: 'x, F, I>(&mut self, b: Breaks, elts: I, op: F)
where F: FnMut(&mut Self, &T), I: IntoIterator<Item = &'x T>,

Source§

#### fn maybe_print_comment(&mut self, pos: BytePos) -> bool

Source§

#### fn print_comment(&mut self, cmnt: Comment)

Source§

#### fn peek_comment<'b>(&'b self) -> Option<&'b Comment>
where 'a: 'b,

Source§

#### fn next_comment(&mut self) -> Option<Comment>

Source§

#### fn maybe_print_trailing_comment( &mut self, span: Span, next_pos: Option<BytePos>, )

Source§

#### fn print_remaining_comments(&mut self)

Source§

#### fn print_string(&mut self, st: &str, style: StrStyle)

Source§

#### fn maybe_print_shebang(&mut self)

Source§

#### fn print_inner_attributes(&mut self, attrs: &[Attribute]) -> bool

Source§

#### fn print_outer_attributes(&mut self, attrs: &[Attribute]) -> bool

Source§

#### fn print_either_attributes( &mut self, attrs: &[Attribute], kind: AttrStyle, is_inline: bool, trailing_hardbreak: bool, ) -> bool

Source§

#### fn print_attribute_inline(&mut self, attr: &Attribute, is_inline: bool) -> bool

Source§

#### fn print_attr_item(&mut self, item: &AttrItem, span: Span)

Source§

#### fn print_tt(&mut self, tt: &TokenTree, convert_dollar_crate: bool) -> Spacing

This doesn’t deserve to be called “pretty” printing, but it should be meaning-preserving. A quick hack that might help would be to look at the spans embedded in the TTs to decide where to put spaces and newlines. But it’d be better to parse these according to the grammar of the appropriate macro, transcribe back into the grammar we just parsed from, and then pretty-print the resulting AST nodes (so, e.g., we print expression arguments as expressions). It can be done! I think.
Source§

#### fn print_tts(&mut self, tts: &TokenStream, convert_dollar_crate: bool)

Source§

#### fn print_mac_common( &mut self, header: Option<MacHeader<'_>>, has_bang: bool, ident: Option<Ident>, delim: Delimiter, open_spacing: Option<Spacing>, tts: &TokenStream, convert_dollar_crate: bool, span: Span, )

Source§

#### fn print_mac_def( &mut self, macro_def: &MacroDef, ident: &Ident, sp: Span, print_visibility: impl FnOnce(&mut Self), )

Source§

#### fn print_path(&mut self, path: &Path, colons_before_params: bool, depth: usize)

Source§

#### fn print_path_segment( &mut self, segment: &PathSegment, colons_before_params: bool, )

Source§

#### fn head<S: Into<Cow<'static, str>>>(&mut self, w: S) -> (BoxMarker, BoxMarker)

Source§

#### fn bopen(&mut self, ib: BoxMarker)

Source§

#### fn bclose_maybe_open( &mut self, span: Span, no_space: bool, cb: Option<BoxMarker>, )

Source§

#### fn bclose(&mut self, span: Span, no_space: bool, cb: BoxMarker)

Source§

#### fn break_offset_if_not_bol(&mut self, n: usize, off: isize)

Source§

#### fn token_kind_to_string(&self, tok: &TokenKind) -> Cow<'static, str>

Print the token kind precisely, without converting `$crate` into its respective crate name.
Source§

#### fn token_kind_to_string_ext( &self, tok: &TokenKind, convert_dollar_crate: Option<Span>, ) -> Cow<'static, str>

Source§

#### fn token_to_string(&self, token: &Token) -> Cow<'static, str>

Print the token precisely, without converting `$crate` into its respective crate name.
Source§

#### fn token_to_string_ext( &self, token: &Token, convert_dollar_crate: bool, ) -> Cow<'static, str>

Source§

#### fn ty_to_string(&self, ty: &Ty) -> String

Source§

#### fn pat_to_string(&self, pat: &Pat) -> String

Source§

#### fn expr_to_string(&self, e: &Expr) -> String

Source§

#### fn meta_item_lit_to_string(&self, lit: &MetaItemLit) -> String

Source§

#### fn stmt_to_string(&self, stmt: &Stmt) -> String

Source§

#### fn item_to_string(&self, i: &Item) -> String

Source§

#### fn assoc_item_to_string(&self, i: &AssocItem) -> String

Source§

#### fn foreign_item_to_string(&self, i: &ForeignItem) -> String

Source§

#### fn path_to_string(&self, p: &Path) -> String

Source§

#### fn vis_to_string(&self, v: &Visibility) -> String

Source§

#### fn block_to_string(&self, blk: &Block) -> String

Source§

#### fn attr_item_to_string(&self, ai: &AttrItem) -> String

Source§

#### fn tts_to_string(&self, tokens: &TokenStream) -> String

Source§

#### fn to_string(f: impl FnOnce(&mut State<'_>)) -> String

## Auto Trait Implementations§

§

### impl<'a> !DynSend for State<'a>

§

### impl<'a> !DynSync for State<'a>

§

### impl<'a> Freeze for State<'a>

§

### impl<'a> !RefUnwindSafe for State<'a>

§

### impl<'a> !Send for State<'a>

§

### impl<'a> !Sync for State<'a>

§

### impl<'a> Unpin for State<'a>

§

### impl<'a> !UnwindSafe for State<'a>

## Blanket Implementations§

§

### impl<T> Aligned for T

§

#### const ALIGN: Alignment

Alignment of `Self`.
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> 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> Pointable for T

Source§

#### const ALIGN: usize

The alignment of pointer.
Source§

#### type Init = T

The type for initializers.
Source§

#### unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

#### unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

#### unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

#### unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

### impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

#### type Target = T

🔬This is a nightly-only experimental API. (`arbitrary_self_types`)
The target type on which the method may be called.
Source§

### impl<T> Same for T

Source§

#### type Output = T

Should always be `Self`
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

## Layout§

Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain `repr(...)` attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.

Size: 248 bytes