Permalink
Browse files

Add generated code logging

  • Loading branch information...
antoyo committed May 7, 2017
1 parent ca5887b commit 2abbdc775c540cceafc9e3f49745b2a9b6a2f3e1
Showing with 20 additions and 0 deletions.
  1. +2 −0 relm-attributes/Cargo.toml
  2. +18 −0 relm-attributes/src/lib.rs
@@ -8,6 +8,8 @@ repository = "https://github.com/antoyo/relm"
version = "0.9.0"
[dependencies]
env_logger = "^0.4.2"
log = "^0.3.7"
quote = "^0.3.15"
syn = "^0.11.9"
View
@@ -21,23 +21,41 @@
#![feature(proc_macro)]
extern crate env_logger;
#[macro_use]
extern crate log;
extern crate proc_macro;
#[macro_use]
extern crate quote;
extern crate relm_gen_widget;
extern crate syn;
use std::env;
use env_logger::LogBuilder;
use log::LogRecord;
use proc_macro::TokenStream;
use relm_gen_widget::gen_widget;
use syn::parse_item;
#[proc_macro_attribute]
pub fn widget(_attributes: TokenStream, input: TokenStream) -> TokenStream {
let format = |record: &LogRecord| {
record.args().to_string()
};
let mut builder = LogBuilder::new();
builder.format(format);
if let Ok(rust_log) = env::var("RUST_LOG") {
builder.parse(&rust_log);
}
builder.init().ok();
let source = input.to_string();
let ast = parse_item(&source).unwrap();
let tokens = quote! {
#ast
};
let expanded = gen_widget(tokens);
error!("{}", expanded.parse::<String>().unwrap());
expanded.parse().unwrap()
}

0 comments on commit 2abbdc7

Please sign in to comment.