aboutsummaryrefslogtreecommitdiffstats
path: root/components/dom_struct/lib.rs
diff options
context:
space:
mode:
authorAnthony Ramine <n.oxyde@gmail.com>2017-09-01 11:43:11 +0200
committerAnthony Ramine <n.oxyde@gmail.com>2017-09-01 12:15:12 +0200
commit5dad4c826d22c2723411d3d50d3eb17b5971ee81 (patch)
treec17ed6bc3e1dd48ea4e8230eec1a67d45828ba91 /components/dom_struct/lib.rs
parent3dceb111587178cdff60041d76a2544f275e6371 (diff)
downloadservo-5dad4c826d22c2723411d3d50d3eb17b5971ee81.tar.gz
servo-5dad4c826d22c2723411d3d50d3eb17b5971ee81.zip
Use the better TokenStream API in dom_struct
Before: ``` error[E0412]: cannot find type `SourceBuffer` in this scope --> /Users/nox/src/servo/components/script/dom/mediasource.rs:25:1 | 25 | #[dom_struct] | ^^^^^^^^^^^^^ did you mean `SourceBufferList`? ``` After: ``` error[E0412]: cannot find type `SourceBuffer` in this scope --> /Users/nox/src/servo/components/script/dom/mediasource.rs:28:39 | 28 | source_buffers: DOMRefCell<Vec<JS<SourceBuffer>>>, | ^^^^^^^^^^^^ did you mean `SourceBufferList`? ```
Diffstat (limited to 'components/dom_struct/lib.rs')
-rw-r--r--components/dom_struct/lib.rs15
1 files changed, 5 insertions, 10 deletions
diff --git a/components/dom_struct/lib.rs b/components/dom_struct/lib.rs
index f74427789db..33801de8c8d 100644
--- a/components/dom_struct/lib.rs
+++ b/components/dom_struct/lib.rs
@@ -5,24 +5,19 @@
#![feature(proc_macro)]
extern crate proc_macro;
-#[macro_use] extern crate quote;
-use proc_macro::TokenStream;
+use proc_macro::{TokenStream, quote};
+use std::iter;
#[proc_macro_attribute]
pub fn dom_struct(args: TokenStream, input: TokenStream) -> TokenStream {
- if !args.to_string().is_empty() {
+ if !args.is_empty() {
panic!("#[dom_struct] takes no arguments");
}
- expand_string(&input.to_string()).parse().unwrap()
-}
-
-fn expand_string(input: &str) -> String {
- let mut tokens = quote! {
+ let attributes = quote! {
#[derive(DenyPublicFields, DomObject, HeapSizeOf, JSTraceable)]
#[must_root]
#[repr(C)]
};
- tokens.append(input);
- tokens.to_string()
+ iter::once(attributes).chain(iter::once(input)).collect()
}