Attribute Macro moretypes::named_tuple

source · []
#[named_tuple]
Expand description

Make a struct into a named tuple, which gives it these properties:

  • A constructor (disable using constructor = false)
  • Methods to convert to and from tuples (disable using tuple_methods = false) All ordering is based on field declaration order, parameters are passed to the attribute

Example

#[moretypes::named_tuple]
#[derive(Debug)]
struct NamedTuple {
    pub x: u32,
    pub y: u32,
}

let named_tuple = NamedTuple::new(35,34);
assert_eq!(named_tuple.x + named_tuple.y, 69, "Named tuple is not nice: {:?}", named_tuple);
assert_eq!(named_tuple.as_tuple(), (35, 34));