pub struct State<'a> {
pub s: Printer,
pub(crate) comments: Option<Comments<'a>>,
pub(crate) attrs: &'a dyn Fn(HirId) -> &'a [Attribute],
pub(crate) ann: &'a (dyn PpAnn + 'a),
}
Fields§
§s: Printer
§comments: Option<Comments<'a>>
§attrs: &'a dyn Fn(HirId) -> &'a [Attribute]
§ann: &'a (dyn PpAnn + 'a)
Implementations§
Source§impl<'a> State<'a>
impl<'a> State<'a>
pub(crate) fn attrs(&self, id: HirId) -> &'a [Attribute]
pub(crate) fn print_node(&mut self, node: Node<'_>)
Source§impl<'a> State<'a>
impl<'a> State<'a>
pub(crate) fn bclose_maybe_open(&mut self, span: Span, close_box: bool)
pub(crate) fn bclose(&mut self, span: Span)
pub(crate) fn commasep_cmnt<T, F, G>( &mut self, b: Breaks, elts: &[T], op: F, get_span: G, )
pub(crate) fn commasep_exprs(&mut self, b: Breaks, exprs: &[Expr<'_>])
pub(crate) fn print_mod(&mut self, _mod: &Mod<'_>, attrs: &[Attribute])
pub(crate) fn print_opt_lifetime(&mut self, lifetime: &Lifetime)
pub(crate) fn print_type(&mut self, ty: &Ty<'_>)
pub(crate) fn print_foreign_item(&mut self, item: &ForeignItem<'_>)
pub(crate) fn print_associated_const( &mut self, ident: Ident, generics: &Generics<'_>, ty: &Ty<'_>, default: Option<BodyId>, )
pub(crate) fn print_associated_type( &mut self, ident: Ident, generics: &Generics<'_>, bounds: Option<GenericBounds<'_>>, ty: Option<&Ty<'_>>, )
pub(crate) fn print_item_type( &mut self, item: &Item<'_>, generics: &Generics<'_>, inner: impl Fn(&mut Self), )
pub(crate) fn print_item(&mut self, item: &Item<'_>)
pub(crate) fn print_trait_ref(&mut self, t: &TraitRef<'_>)
pub(crate) fn print_opaque_ty(&mut self, o: &OpaqueTy<'_>)
pub(crate) fn print_formal_generic_params( &mut self, generic_params: &[GenericParam<'_>], )
pub(crate) fn print_poly_trait_ref(&mut self, t: &PolyTraitRef<'_>)
pub(crate) fn print_enum_def( &mut self, enum_definition: &EnumDef<'_>, generics: &Generics<'_>, name: Symbol, span: Span, )
pub(crate) fn print_variants(&mut self, variants: &[Variant<'_>], span: Span)
pub(crate) fn print_defaultness(&mut self, defaultness: Defaultness)
pub(crate) fn print_struct( &mut self, struct_def: &VariantData<'_>, generics: &Generics<'_>, name: Symbol, span: Span, print_finalizer: bool, )
pub(crate) fn print_variant_struct( &mut self, span: Span, fields: &[FieldDef<'_>], )
pub fn print_variant(&mut self, v: &Variant<'_>)
pub(crate) fn print_method_sig( &mut self, ident: Ident, m: &FnSig<'_>, generics: &Generics<'_>, arg_names: &[Ident], body_id: Option<BodyId>, )
pub(crate) fn print_trait_item(&mut self, ti: &TraitItem<'_>)
pub(crate) fn print_impl_item(&mut self, ii: &ImplItem<'_>)
pub(crate) fn print_local( &mut self, init: Option<&Expr<'_>>, els: Option<&Block<'_>>, decl: impl Fn(&mut Self), )
pub(crate) fn print_stmt(&mut self, st: &Stmt<'_>)
pub(crate) fn print_block(&mut self, blk: &Block<'_>)
pub(crate) fn print_block_unclosed(&mut self, blk: &Block<'_>)
pub(crate) fn print_block_with_attrs( &mut self, blk: &Block<'_>, attrs: &[Attribute], )
pub(crate) fn print_block_maybe_unclosed( &mut self, blk: &Block<'_>, attrs: &[Attribute], close_box: bool, )
pub(crate) fn print_else(&mut self, els: Option<&Expr<'_>>)
pub(crate) fn print_if( &mut self, test: &Expr<'_>, blk: &Expr<'_>, elseopt: Option<&Expr<'_>>, )
pub(crate) fn print_array_length(&mut self, len: &ArrayLen<'_>)
pub(crate) fn print_anon_const(&mut self, constant: &AnonConst)
pub(crate) fn print_const_arg(&mut self, const_arg: &ConstArg<'_>)
pub(crate) fn print_call_post(&mut self, args: &[Expr<'_>])
pub(crate) fn print_expr_maybe_paren(&mut self, expr: &Expr<'_>, prec: i8)
Sourcepub(crate) fn print_expr_as_cond(&mut self, expr: &Expr<'_>)
pub(crate) 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 { ... }
.
Sourcepub(crate) fn print_expr_cond_paren(&mut self, expr: &Expr<'_>, needs_par: bool)
pub(crate) fn print_expr_cond_paren(&mut self, expr: &Expr<'_>, needs_par: bool)
Prints expr
or (expr)
when needs_par
holds.
Sourcepub(crate) fn print_let(
&mut self,
pat: &Pat<'_>,
ty: Option<&Ty<'_>>,
init: &Expr<'_>,
)
pub(crate) fn print_let( &mut self, pat: &Pat<'_>, ty: Option<&Ty<'_>>, init: &Expr<'_>, )
Print a let pat = expr
expression.
pub(crate) fn cond_needs_par(expr: &Expr<'_>) -> bool
pub(crate) fn print_expr_vec(&mut self, exprs: &[Expr<'_>])
pub(crate) fn print_inline_const(&mut self, constant: &ConstBlock)
pub(crate) fn print_expr_repeat( &mut self, element: &Expr<'_>, count: &ArrayLen<'_>, )
pub(crate) fn print_expr_struct( &mut self, qpath: &QPath<'_>, fields: &[ExprField<'_>], wth: Option<&Expr<'_>>, )
pub(crate) fn print_expr_field(&mut self, field: &ExprField<'_>)
pub(crate) fn print_expr_tup(&mut self, exprs: &[Expr<'_>])
pub(crate) fn print_expr_call(&mut self, func: &Expr<'_>, args: &[Expr<'_>])
pub(crate) fn print_expr_method_call( &mut self, segment: &PathSegment<'_>, receiver: &Expr<'_>, args: &[Expr<'_>], )
pub(crate) fn print_expr_binary( &mut self, op: BinOp, lhs: &Expr<'_>, rhs: &Expr<'_>, )
pub(crate) fn print_expr_unary(&mut self, op: UnOp, expr: &Expr<'_>)
pub(crate) fn print_expr_addr_of( &mut self, kind: BorrowKind, mutability: Mutability, expr: &Expr<'_>, )
pub(crate) fn print_literal(&mut self, lit: &Lit)
pub(crate) fn print_inline_asm(&mut self, asm: &InlineAsm<'_>)
pub(crate) fn print_expr(&mut self, expr: &Expr<'_>)
pub(crate) fn print_local_decl(&mut self, loc: &LetStmt<'_>)
pub(crate) fn print_name(&mut self, name: Symbol)
pub(crate) fn print_path<R>( &mut self, path: &Path<'_, R>, colons_before_params: bool, )
pub(crate) fn print_path_segment(&mut self, segment: &PathSegment<'_>)
pub(crate) fn print_qpath( &mut self, qpath: &QPath<'_>, colons_before_params: bool, )
pub(crate) fn print_generic_args( &mut self, generic_args: &GenericArgs<'_>, colons_before_params: bool, )
pub(crate) fn print_assoc_item_constraint( &mut self, constraint: &AssocItemConstraint<'_>, )
pub(crate) fn print_pat(&mut self, pat: &Pat<'_>)
pub(crate) fn print_patfield(&mut self, field: &PatField<'_>)
pub(crate) fn print_param(&mut self, arg: &Param<'_>)
pub(crate) fn print_arm(&mut self, arm: &Arm<'_>)
pub(crate) fn print_fn( &mut self, decl: &FnDecl<'_>, header: FnHeader, name: Option<Symbol>, generics: &Generics<'_>, arg_names: &[Ident], body_id: Option<BodyId>, )
pub(crate) fn print_closure_params( &mut self, decl: &FnDecl<'_>, body_id: BodyId, )
pub(crate) fn print_capture_clause(&mut self, capture_clause: CaptureBy)
pub(crate) fn print_closure_binder( &mut self, binder: ClosureBinder, generic_params: &[GenericParam<'_>], )
pub(crate) fn print_bounds<'b>( &mut self, prefix: &'static str, bounds: impl IntoIterator<Item = &'b GenericBound<'b>>, )
pub(crate) fn print_precise_capturing_arg( &mut self, arg: PreciseCapturingArg<'_>, )
pub(crate) fn print_generic_params( &mut self, generic_params: &[GenericParam<'_>], )
pub(crate) fn print_generic_param(&mut self, param: &GenericParam<'_>)
pub(crate) fn print_lifetime(&mut self, lifetime: &Lifetime)
pub(crate) fn print_where_clause(&mut self, generics: &Generics<'_>)
pub(crate) fn print_mutability(&mut self, mutbl: Mutability, print_const: bool)
pub(crate) fn print_mt(&mut self, mt: &MutTy<'_>, print_const: bool)
pub(crate) fn print_fn_output(&mut self, decl: &FnDecl<'_>)
pub(crate) fn print_ty_fn( &mut self, abi: ExternAbi, safety: Safety, decl: &FnDecl<'_>, name: Option<Symbol>, generic_params: &[GenericParam<'_>], arg_names: &[Ident], )
pub(crate) fn print_fn_header_info(&mut self, header: FnHeader)
pub(crate) fn print_constness(&mut self, s: Constness)
pub(crate) fn print_safety(&mut self, s: Safety)
pub(crate) fn print_is_auto(&mut self, s: IsAuto)
Methods from Deref<Target = Printer>§
pub fn word_space<W>(&mut self, w: W)
pub fn popen(&mut self)
pub fn pclose(&mut self)
pub fn hardbreak_if_not_bol(&mut self)
pub fn space_if_not_bol(&mut self)
pub fn nbsp(&mut self)
pub fn word_nbsp<S>(&mut self, w: S)
pub fn synth_comment(&mut self, text: impl Into<Cow<'static, str>>)
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.
pub fn visual_align(&mut self)
pub fn break_offset(&mut self, n: usize, off: isize)
pub fn end(&mut self)
pub fn word<S>(&mut self, wrd: S)
pub fn zerobreak(&mut self)
pub fn space(&mut self)
pub fn hardbreak(&mut self)
pub fn is_beginning_of_line(&self) -> bool
pub fn trailing_comma(&mut self)
pub fn trailing_comma_or_space(&mut self)
Trait Implementations§
Source§impl<'a> PrintState<'a> for State<'a>
impl<'a> PrintState<'a> for State<'a>
fn comments(&self) -> Option<&Comments<'a>>
fn comments_mut(&mut self) -> Option<&mut Comments<'a>>
fn ann_post(&mut self, ident: Ident)
fn print_generic_args(&mut self, _: &GenericArgs, _colons_before_params: bool)
fn print_ident(&mut self, ident: Ident)
fn strsep<T, F>( &mut self, sep: &'static str, space_before: bool, b: Breaks, elts: &[T], op: F, )
fn commasep<T, F>(&mut self, b: Breaks, elts: &[T], op: F)
fn maybe_print_comment(&mut self, pos: BytePos) -> bool
fn print_comment(&mut self, cmnt: Comment)
fn peek_comment<'b>(&'b self) -> Option<&'b Comment>where
'a: 'b,
fn next_comment(&mut self) -> Option<Comment>
fn maybe_print_trailing_comment( &mut self, span: Span, next_pos: Option<BytePos>, )
fn print_remaining_comments(&mut self)
fn print_string(&mut self, st: &str, style: StrStyle)
fn print_inner_attributes(&mut self, attrs: &[Attribute]) -> bool
fn print_outer_attributes(&mut self, attrs: &[Attribute]) -> bool
fn print_either_attributes( &mut self, attrs: &[Attribute], kind: AttrStyle, is_inline: bool, trailing_hardbreak: bool, ) -> bool
fn print_attribute_inline(&mut self, attr: &Attribute, is_inline: bool)
fn print_attr_item(&mut self, item: &AttrItem, span: Span)
§fn print_tt(&mut self, tt: &TokenTree, convert_dollar_crate: bool) -> Spacing
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.
fn print_tts(&mut self, tts: &TokenStream, convert_dollar_crate: bool)
fn print_mac_common( &mut self, header: Option<MacHeader<'_>>, has_bang: bool, ident: Option<Ident>, delim: Delimiter, tts: &TokenStream, convert_dollar_crate: bool, span: Span, )
fn print_mac_def( &mut self, macro_def: &MacroDef, ident: &Ident, sp: Span, print_visibility: impl FnOnce(&mut Self), )
fn print_path(&mut self, path: &Path, colons_before_params: bool, depth: usize)
fn print_path_segment( &mut self, segment: &PathSegment, colons_before_params: bool, )
fn head<S>(&mut self, w: S)
fn bopen(&mut self)
fn bclose_maybe_open(&mut self, span: Span, empty: bool, close_box: bool)
fn bclose(&mut self, span: Span, empty: bool)
fn break_offset_if_not_bol(&mut self, n: usize, off: isize)
fn nonterminal_to_string(&self, nt: &Nonterminal) -> String
§fn token_kind_to_string(&self, tok: &TokenKind) -> Cow<'static, str>
fn token_kind_to_string(&self, tok: &TokenKind) -> Cow<'static, str>
Print the token kind precisely, without converting
$crate
into its respective crate name.fn token_kind_to_string_ext( &self, tok: &TokenKind, convert_dollar_crate: Option<Span>, ) -> Cow<'static, str>
§fn token_to_string(&self, token: &Token) -> Cow<'static, str>
fn token_to_string(&self, token: &Token) -> Cow<'static, str>
Print the token precisely, without converting
$crate
into its respective crate name.fn token_to_string_ext( &self, token: &Token, convert_dollar_crate: bool, ) -> Cow<'static, str>
fn ty_to_string(&self, ty: &Ty) -> String
fn pat_to_string(&self, pat: &Pat) -> String
fn expr_to_string(&self, e: &Expr) -> String
fn meta_item_lit_to_string(&self, lit: &MetaItemLit) -> String
fn stmt_to_string(&self, stmt: &Stmt) -> String
fn item_to_string(&self, i: &Item) -> String
fn path_to_string(&self, p: &Path) -> String
fn vis_to_string(&self, v: &Visibility) -> String
fn block_to_string(&self, blk: &Block) -> String
fn attr_item_to_string(&self, ai: &AttrItem) -> String
fn tts_to_string(&self, tokens: &TokenStream) -> String
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§
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
Mutably borrows from an owned value. Read more
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>
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 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>
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
Source§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
Source§fn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
impl<'a, T> Captures<'a> for Twhere
T: ?Sized,
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: 256 bytes