token_stream2

Crates.iotoken_stream2
lib.rstoken_stream2
version1.0.2
sourcesrc
created_at2023-06-29 19:31:08.046383
updated_at2023-06-29 22:52:57.935437
descriptionA better TokenStream for procedural macros.
homepage
repositoryhttps://github.com/realmofuz/token_stream2
max_upload_size
id903601
size26,502
Endistic (akarahdev)

documentation

https://docs.rs/token_stream2/

README

tokenstream2

token_stream2 is a helper crate for parsing procedural macros. It allows you to quickly convert from proc_macro2::TokenStream into a token_stream2::TokenStream, which allows you to have a much easier time traversing the token stream. It's also extremely lightweight with only one dependency, proc_macro2, which you most likely already have.

Usage

You can easily convert into tokenstream2::TokenStream using .into().

let to_parse: proc_macro2::TokenStream = r#"
        fn main() {
            println!("Hello world!");
        }
    "#
    .parse()
    .expect("infallible");

let stream: token_stream2::TokenStream = to_parse.into();

token_stream2::TokenStream implements Iterator, so you can use the various Iterator methods on it.

It also has it's own .peek() method you can use to quickly look ahead, since that will likely be a common behavior.

Examples

You can look in the /examples directory to see an example of it in use.

Commit count: 8

cargo fmt