nightly proc-macro-faithful-display

A Display implementation for proc-macro types more faithful to the input stream

1 unstable release

0.1.0 Dec 1, 2018

#251 in #proc-macro

Download history 13/week @ 2022-06-11 21/week @ 2022-06-18 14/week @ 2022-06-25 17/week @ 2022-07-02 14/week @ 2022-07-09 15/week @ 2022-07-16 17/week @ 2022-07-23 20/week @ 2022-07-30 24/week @ 2022-08-06 20/week @ 2022-08-13 17/week @ 2022-08-20 19/week @ 2022-08-27 20/week @ 2022-09-03 20/week @ 2022-09-10 17/week @ 2022-09-17 18/week @ 2022-09-24

78 downloads per month
Used in 2 crates


116 lines

A more faithful Display implementation for proc-macro types

This crate provides a faithful implementation of display regarding the input token stream. That is, the display formatted output will contain the same spaces and newlines as the input flow of Rust tokens.

Feel free to browse the documentation for further details.


An alternative [Display] impl for [proc_macro], respecting the input layout and formatting.

The idea is that the impl of [Display] for [proc_macro] types doesn’t respect the input’s layout. For most commun Rust use cases, this is okay, because the language doesn’t depend on whitespaces and has its own grammar for floating point numbers, field access, etc. However, for all other use cases, you will lose your formatting and indentation. Plus, some EDSLs might require strict use of newlines or symbols with a leading colon, comma, etc. without whitespaces.

This crate provides an implementation of [Display] that respects the input’s formatting, so that one can display a [TokenStream] and parse it with a more esoteric parser than syn.

Currently, this crate highly depends on nightly features. You cannot use it on the stable channel… just yet.

You can get a faithful [Display] object by calling the [faithful_display] function on your [TokenStream].

At the time of writing, traits don’t allow existential impl Trait to be used in methods. This is unfortunate, then the feature is accessed through a function instead of a method.

No runtime deps