Skip to content
This repository was archived by the owner on Oct 10, 2019. It is now read-only.

Commit 50d93bd

Browse files
committed
Update to new attribute whitelisting setup
1 parent c874cd4 commit 50d93bd

File tree

2 files changed

+6
-29
lines changed

2 files changed

+6
-29
lines changed

postgres-derive/Cargo.toml

-2
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ test = false
1414

1515
[dependencies]
1616
postgres-derive-internals = { version = "0.2.0", path = "../postgres-derive-internals" }
17-
post-expansion = "0.2"
1817
syn = "0.10"
19-
quote = "0.3"
2018

2119
[dev-dependencies]
2220
postgres = "0.12"

postgres-derive/src/lib.rs

+6-27
Original file line numberDiff line numberDiff line change
@@ -2,45 +2,24 @@
22

33
extern crate proc_macro;
44
extern crate postgres_derive_internals;
5-
#[macro_use]
6-
extern crate post_expansion;
5+
76
extern crate syn;
8-
extern crate quote;
97

108
use proc_macro::TokenStream;
11-
use quote::{ToTokens, Tokens};
12-
13-
register_post_expansion!(PostExpansion_postgres_derive);
149

15-
#[proc_macro_derive(ToSql)]
10+
#[proc_macro_derive(ToSql, attributes(postgres))]
1611
pub fn derive_tosql(input: TokenStream) -> TokenStream {
1712
derive(input, postgres_derive_internals::expand_derive_tosql)
1813
}
1914

20-
#[proc_macro_derive(FromSql)]
15+
#[proc_macro_derive(FromSql, attributes(postgres))]
2116
pub fn derive_fromsql(input: TokenStream) -> TokenStream {
2217
derive(input, postgres_derive_internals::expand_derive_fromsql)
2318
}
2419

2520
fn derive(input: TokenStream, expand: fn(&str) -> Result<String, String>) -> TokenStream {
26-
let source = input.to_string();
27-
28-
let decl = expand_decl(&source);
29-
30-
let impl_ = match expand(&source) {
31-
Ok(impl_) => impl_,
21+
match expand(&input.to_string()) {
22+
Ok(impl_) => impl_.parse().unwrap(),
3223
Err(e) => panic!("{}", e),
33-
};
34-
35-
let expanded = format!("{}\n{}", decl, impl_);
36-
expanded.parse().unwrap()
37-
}
38-
39-
fn expand_decl(source: &str) -> String {
40-
let ast = syn::parse_macro_input(source).unwrap();
41-
let stripped = post_expansion::strip_attrs_later(ast, &["postgres"], "postgres_derive");
42-
43-
let mut tokens = Tokens::new();
44-
stripped.to_tokens(&mut tokens);
45-
tokens.to_string()
24+
}
4625
}

0 commit comments

Comments
 (0)