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`?
```
This commit is contained in:
Anthony Ramine 2017-09-01 11:43:11 +02:00
parent 3dceb11158
commit 5dad4c826d
3 changed files with 5 additions and 16 deletions

View file

@ -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()
}