qq 0.1.1

lightweight alternative quote
Documentation

Quasi-Quote

This is an alternative to quote that doesn't rely on proc-macro2. It also uses a slightly different syntax that allows interposing control flow and quoted code.

How?

The basics are as follows: The QuoteExt trait contains the most immediately useful methods, and the qq! macro converts its input tokens into a type that implements Quote (and thus QuoteExt).

A simple example:

use qq::{qq, QuoteExt};

#[proc_macro]
pub fn generate_echo(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
	qq!(fn output() {
		~for (i, tok) in (input.into_iter().enumerate()) {
			println!(~(format!("Token {i} was {tok}")));
		}
	}).quote()
}

For more details, refer to the crate documentation.

Why?

These are some possible motivations for using this crate:

  • You want to write a procedural macro with minimal dependencies.
  • You have read the source code of quote and/or proc-macro2 and were rightly horrified.
  • You dislike having to do all control flow before invoking quote::quote!.