[][src]Macro neli::impl_var

macro_rules! impl_var {
    ( $( #[$outer:meta] )*
      $name:ident, $ty:ty, $var_def:ident => $val_def:expr,
      $( $var:ident => $val:expr ),* ) => { ... };
    ( $name:ident, $ty:ty, $var_def:ident => $val_def:expr,
      $( $var:ident => $val:expr ),* ) => { ... };
}

For naming a new enum, passing in what type it serializes to and deserializes from, and providing a mapping from variants to expressions (such as libc consts) that will ultimately be used in the serialization/deserialization step when sending the netlink message over the wire.

Usage

Create an enum named "MyNetlinkProtoAttrs" that can be serialized into u16s to use with Netlink. Possibly represents the fields on a message you received from Netlink.

This example is not tested
impl_var!(MyNetlinkProtoAttrs, u16,
   Id => 16 as u16,
   Name => 17 as u16,
   Size => 18 as u16
);

Or, with doc comments (if you're developing a library)

This example is not tested
 impl_var!(
    /// These are the attributes returned
    /// by a fake netlink protocol.
    ( MyNetlinkProtoAttrs, u16,
    Id => 16 as u16,
    Name => 17 as u16,
    Size => 18 as u16 )
 );