Skip to main content

## PrintState

# Trait PrintState

Source

    pub trait PrintState<'a>: Deref<Target = Printer> + DerefMut {
    Show 51 methods    // Required methods
        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,
            args: &GenericArgs,
            colons_before_params: bool,
        );

        // Provided methods
        fn print_ident(&mut self, ident: Ident) { ... }
        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> { ... }
        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> { ... }
        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 maybe_print_shebang(&mut self) { ... }
        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,
        ) -> 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_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,
            open_spacing: Option<Spacing>,
            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: Into<Cow<'static, str>>>(
            &mut self,
            w: S,
        ) -> (BoxMarker, BoxMarker) { ... }
        fn bopen(&mut self, ib: BoxMarker) { ... }
        fn bclose_maybe_open(
            &mut self,
            span: Span,
            no_space: bool,
            cb: Option<BoxMarker>,
        ) { ... }
        fn bclose(&mut self, span: Span, no_space: bool, cb: BoxMarker) { ... }
        fn break_offset_if_not_bol(&mut self, n: usize, off: isize) { ... }
        fn token_kind_to_string(&self, tok: &TokenKind) -> Cow<'static, str> { ... }
        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_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 assoc_item_to_string(&self, i: &AssocItem) -> String { ... }
        fn foreign_item_to_string(&self, i: &ForeignItem) -> String { ... }
        fn path_to_string(&self, p: &Path) -> String { ... }
        fn vis_to_string(&self, v: &Visibility) -> String { ... }
        fn impl_restriction_to_string(&self, r: &ImplRestriction) -> String { ... }
        fn mut_restriction_to_string(&self, r: &MutRestriction) -> 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 { ... }
    }

Expand description

This trait is used for both AST and HIR pretty-printing.

## Required Methods§

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)

## Provided Methods§

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 impl_restriction_to_string(&self, r: &ImplRestriction) -> String

Source

#### fn mut_restriction_to_string(&self, r: &MutRestriction) -> 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

## Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

## Implementors§

Source§

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