[][src]Macro intrusive_collections::intrusive_adapter

macro_rules! intrusive_adapter {
    (@impl
        ($($privacy:tt)*) $name:ident ($($args:tt $(: ?$bound:tt)*),*)
        = $pointer:ty: $value:path { $field:ident: $link:ty } $($where_: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)*) $name:tt < $($rest:tt)*
    ) => { ... };
    (@find_if_generic
        ($($privacy:tt)*) $name:tt $($rest:tt)*
    ) => { ... };
    (pub $name:tt $($rest:tt)*) => { ... };
    ($name: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:

This example is not tested
intrusive_adapter!(Adapter = Pointer: Value { link_field: LinkType });

You can create a new instance of an adapter using the new method or the NEW associated constant. The adapter also implements the Default trait.

Generics

This macro supports generic arguments:

This example is not tested
intrusive_adapter!(
    Adapter<'lifetime, Type, Type2: ?Sized> =
        Pointer: Value {
            link_field: LinkType
        }
        where
            Type: Copy,
            Type2: 'lifetime
    );

Note that due to macro parsing limitations, only ?Trait style bounds are allowed in the generic argument list. In most cases this is only needed for ?Sized. Other bounds can be specified in the where clause at the end the macro.

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);