#quote #fork #temporary #futures-await #tokens #dtolnay-quote

futures-await-quote

Temporary fork of the quote crate for futures-await

1 unstable release

Uses old Rust 2015

0.4.0 Oct 28, 2017

#4 in #futures-await

Download history 14/week @ 2023-12-03 33/week @ 2023-12-10 41/week @ 2023-12-17 34/week @ 2023-12-24 5/week @ 2023-12-31 27/week @ 2024-01-07 34/week @ 2024-01-14 26/week @ 2024-01-21 9/week @ 2024-01-28 23/week @ 2024-02-04 36/week @ 2024-02-11 53/week @ 2024-02-18 52/week @ 2024-02-25 45/week @ 2024-03-03 55/week @ 2024-03-10 58/week @ 2024-03-17

212 downloads per month
Used in 3 crates

MIT/Apache

21KB
528 lines

futures-await-quote

This crate is a temporary fork of dtolnay/quote. The quote repository isn't ready for publication yet but we'd like to publish the futures-await crate. This is a temporary fork that will only be maintained for the futures-await crate and it will be unmaintained as soon as quote is published upstream.

License

Licensed under either of

at your option.


lib.rs:

Quasi-quoting without a Syntex dependency, intended for use with Macros 1.1.

[dependencies]
quote = "0.3"
#[macro_use]
extern crate quote;

Interpolation is done with #var:

let tokens = quote! {
    struct SerializeWith #generics #where_clause {
        value: &'a #field_ty,
        phantom: ::std::marker::PhantomData<#item_ty>,
    }

    impl #generics serde::Serialize for SerializeWith #generics #where_clause {
        fn serialize<S>(&self, s: &mut S) -> Result<(), S::Error>
            where S: serde::Serializer
        {
            #path(self.value, s)
        }
    }

    SerializeWith {
        value: #value,
        phantom: ::std::marker::PhantomData::<#item_ty>,
    }
};

Repetition is done using #(...)* or #(...),* very similar to macro_rules!:

  • #(#var)* - no separators
  • #(#var),* - the character before the asterisk is used as a separator
  • #( struct #var; )* - the repetition can contain other things
  • #( #k => println!("{}", #v), )* - even multiple interpolations

The return type of quote! is quote::Tokens. Tokens can be interpolated into other quotes:

let t = quote! { /* ... */ };
return quote! { /* ... */ #t /* ... */ };

Call to_string() or as_str() on a Tokens to get a String or &str of Rust code.

The quote! macro relies on deep recursion so some large invocations may fail with "recursion limit reached" when you compile. If it fails, bump up the recursion limit by adding #![recursion_limit = "128"] to your crate. An even higher limit may be necessary for especially large invocations.

Dependencies

~220KB