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

#29 in #proc-macro

Download history 10/week @ 2018-12-01

3 downloads per month
Used in 1 crate


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