Macro grafen::create_entry_wrapper [] [src]

macro_rules! create_entry_wrapper {
    (
        $name:ident, // enum Identifier
        $( ($class:path => $entry:ident) ),+ // Identifier::Entry(Class)
    ) => { ... };
}

Macro to wrap every object constructor into an enum with desired traits.

The traits are those important for the creation and display of system components. The enum is used to hold created objects of different types in one container, sharing one interface.

Implements Describe, Component and Translate for the enum.

Also sets up some getter functions directly to the object data and the with_pbc method to move residue coordinates within the box.

Requires

Wrapped objects have to implement the above traits and Clone, Debug, Deserialize and Serialize (the last two from serde).

Examples

Create two objects and let the macro create the wrapper and implement the traits for it.

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct StructOne {
    origin: Coord,
    residue: Option<Residue>,
    coords: Vec<Coord>
}

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct StructTwo {
    origin: Coord,
    residue: Option<Residue>,
    coords: Vec<Coord>
}

// Not shown: implement required traits

// Construct the wrapping enum container
create_entry_wrapper![
    Wrapper, // enum identifier
    (StructOne => One), // Wrapper::One(StructOne)
    (StructTwo => Two)  // Wrapper::Two(StructTwo)
];

let objects = vec![
    Wrapper::One(StructOne {
        origin: Coord::default(),
        residue: None,
        coords: vec![]
    }),
    Wrapper::Two(StructTwo {
        origin: Coord::default(),
        residue: None,
        coords: vec![]
    })
];

assert_eq!("StructOne", &objects[0].describe());
assert_eq!(None, objects[0].iter_atoms().next());

assert_eq!("StructTwo", &objects[1].describe());
assert_eq!(None, objects[1].iter_atoms().next());