scoped_gc_derive/
lib.rs

1extern crate proc_macro2;
2#[macro_use]
3extern crate quote;
4extern crate syn;
5#[macro_use]
6extern crate synstructure;
7
8decl_derive!([Trace] => derive_trace);
9
10fn derive_trace(s: synstructure::Structure) -> quote::Tokens {
11  let trace_body = s.each(|bi| quote!(mark(#bi)));
12
13  let trace_impl = s.unsafe_bound_impl(quote!(::scoped_gc::Trace), quote! {
14    #[inline] unsafe fn mark(&self) {
15      #[allow(dead_code)]
16      #[inline]
17      unsafe fn mark<T: ::scoped_gc::Trace>(it: &T) {
18        ::scoped_gc::Trace::mark(it);
19      }
20      match *self { #trace_body }
21    }
22    #[inline] unsafe fn root(&self) {
23      #[allow(dead_code)]
24      #[inline]
25      unsafe fn mark<T: ::scoped_gc::Trace>(it: &T) {
26        ::scoped_gc::Trace::root(it);
27      }
28      match *self { #trace_body }
29    }
30    #[inline] unsafe fn unroot(&self) {
31      #[allow(dead_code)]
32      #[inline]
33      unsafe fn mark<T: ::scoped_gc::Trace>(it: &T) {
34        ::scoped_gc::Trace::unroot(it);
35      }
36      match *self { #trace_body }
37    }
38  });
39
40  quote! { #trace_impl }
41}