Macro intrusive_collections::intrusive_adapter
[−]
[src]
macro_rules! intrusive_adapter { (@impl [($($privacy:tt)*) ($name:ident) ($($args:tt $(: ?$bound:tt)*),*)] ($pointer:ty: $value:path { $field:ident: $link:ty } $($where_:tt)*) ) => { ... }; (@impl $tokens:tt) => { ... }; (@find_generic [($($privacy:tt)*) ($($name:tt)*) ($($prev:tt)*)] (> = $($rest:tt)*) ) => { ... }; (@find_generic [($($privacy:tt)*) ($($name:tt)*) ($($prev:tt)*)] ($cur:tt $($rest:tt)*) ) => { ... }; (@find_if_generic [($($privacy:tt)*) ($($prev:tt)*)] () ) => { ... }; (@find_if_generic [($($privacy:tt)*) ($($prev:tt)*)] (= $($rest:tt)*) ) => { ... }; (@find_if_generic [($($privacy:tt)*) ($($prev:tt)*)] (< $($rest:tt)*) ) => { ... }; (@find_if_generic [($($privacy:tt)*) ($($prev:tt)*)] ($cur:tt $($rest:tt)*) ) => { ... }; (pub $($rest:tt)*) => { ... }; ($($rest:tt)*) => { ... }; }
Macro to generate an implementation of Adapter
for a given set of types.
In particular this will automatically generate implementations of the
get_value
and get_link
methods for a given named field in a struct.
The basic syntax to create an adapter is:
rust,ignore intrusive_adapter!(Adapter = Pointer: Value { link_field: LinkType });
Generics
This macro supports generic arguments:
rust,ignore intrusive_adapter!(Adapter<'lifetime, Type, Type2: ?Sized> = Pointer: Value { link_field: LinkType } where Type: Copy, Type2: 'lifetiem);
Examples
#[macro_use] extern crate intrusive_collections; use intrusive_collections::{LinkedListLink, RBTreeLink}; pub struct Test { link: LinkedListLink, link2: RBTreeLink, } intrusive_adapter!(MyAdapter = Box<Test>: Test { link: LinkedListLink }); intrusive_adapter!(pub MyAdapter2 = Box<Test>: Test { link2: RBTreeLink }); pub struct Test2<T: ?Sized> where T: Clone { link: LinkedListLink, val: T, } intrusive_adapter!(MyAdapter3<'a, T: ?Sized> = &'a Test2<T>: Test2<T> { link: LinkedListLink } where T: Clone + 'a);