mirror of
https://github.com/danog/strum.git
synced 2024-11-30 04:28:59 +01:00
Added better support for debugging items
This commit is contained in:
parent
088ca638e6
commit
ef401fcd27
@ -280,6 +280,12 @@ fn main() {
|
||||
}
|
||||
```
|
||||
|
||||
# Debugging
|
||||
|
||||
To see the generated code, set the DEBUG_STRUM environment variable before compiling your code.
|
||||
`DEBUG_STRUM=1` will dump all of the generated code for every type. `DEBUG_STRUM=YourType` will
|
||||
only dump the code generated on a type named `YourType`.
|
||||
|
||||
# Name
|
||||
|
||||
Strum is short for STRing enUM because it's a library for augmenting enums with additional
|
||||
|
@ -276,6 +276,12 @@
|
||||
//! }
|
||||
//! ```
|
||||
//!
|
||||
//! # Debugging
|
||||
//!
|
||||
//! To see the generated code, set the DEBUG_STRUM environment variable before compiling your code.
|
||||
//! `DEBUG_STRUM=1` will dump all of the generated code for every type. `DEBUG_STRUM=YourType` will
|
||||
//! only dump the code generated on a type named YourType.
|
||||
//!
|
||||
//! # Name
|
||||
//!
|
||||
//! Strum is short for STRing enUM because it's a library for augmenting enums with additional
|
||||
|
@ -14,6 +14,7 @@ extern crate proc_macro;
|
||||
|
||||
use proc_macro::TokenStream;
|
||||
use syn::Attribute;
|
||||
use std::env;
|
||||
|
||||
#[proc_macro_derive(EnumString,attributes(strum))]
|
||||
pub fn from_string(input: TokenStream) -> TokenStream {
|
||||
@ -21,6 +22,7 @@ pub fn from_string(input: TokenStream) -> TokenStream {
|
||||
let ast = syn::parse_derive_input(&s).unwrap();
|
||||
|
||||
let toks = from_string_inner(&ast);
|
||||
debug_print_generated(&ast, &toks);
|
||||
toks.parse().unwrap()
|
||||
}
|
||||
|
||||
@ -30,6 +32,7 @@ pub fn enum_iter(input: TokenStream) -> TokenStream {
|
||||
let ast = syn::parse_derive_input(&s).unwrap();
|
||||
|
||||
let toks = enum_iter_inner(&ast);
|
||||
debug_print_generated(&ast, &toks);
|
||||
toks.parse().unwrap()
|
||||
}
|
||||
|
||||
@ -39,9 +42,24 @@ pub fn enum_messages(input: TokenStream) -> TokenStream {
|
||||
let ast = syn::parse_derive_input(&s).unwrap();
|
||||
|
||||
let toks = enum_message_inner(&ast);
|
||||
debug_print_generated(&ast, &toks);
|
||||
toks.parse().unwrap()
|
||||
}
|
||||
|
||||
fn debug_print_generated(ast: &syn::DeriveInput, toks: "e::Tokens) {
|
||||
let ident = ast.ident.as_ref();
|
||||
let debug = env::var("STRUM_DEBUG");
|
||||
if let Ok(s) = debug {
|
||||
if s == "1" {
|
||||
println!("{}", toks);
|
||||
}
|
||||
|
||||
if s == ident {
|
||||
println!("{}", toks);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn extract_attrs<'a>(attrs: &'a [Attribute], attr: &str, prop: &str) -> Vec<&'a str> {
|
||||
attrs.iter()
|
||||
// Get all the attributes with our tag on them.
|
||||
|
Loading…
Reference in New Issue
Block a user