#proc-macro #display #input #input-stream #faithful #token #type

nightly proc-macro-faithful-display

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

2 unstable releases

0.2.0 Dec 19, 2023
0.1.0 Dec 1, 2018

#278 in Procedural macros

Download history 6/week @ 2023-12-22 17/week @ 2024-02-16 48/week @ 2024-02-23 30/week @ 2024-03-01 29/week @ 2024-03-08 13/week @ 2024-03-15 1/week @ 2024-03-22 33/week @ 2024-03-29 11/week @ 2024-04-05

74 downloads per month
Used in 2 crates

BSD-3-Clause

11KB
138 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.


lib.rs:

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