mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
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:
parent
3dceb11158
commit
5dad4c826d
3 changed files with 5 additions and 16 deletions
|
@ -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()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue