Go to file
2016-10-09 14:18:51 -07:00
src Underscore the loop variable 2016-10-08 16:21:10 -07:00
tests Underscore the loop variable 2016-10-08 16:21:10 -07:00
.gitignore quote! 2016-09-02 22:37:51 -07:00
.travis.yml Add Travis build 2016-09-07 08:40:22 -07:00
Cargo.toml Add "syn" as crates.io keyword 2016-10-09 14:18:51 -07:00
LICENSE-APACHE quote! 2016-09-02 22:37:51 -07:00
LICENSE-MIT quote! 2016-09-02 22:37:51 -07:00
README.md Bump version in readme 2016-10-08 14:55:59 -07:00

Dead Simple Rust Quasi-Quoting

Build Status Latest Version Rust Documentation

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

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.