Attribute Macro named_tup::tup_default

source · []
#[tup_default]
Expand description

An attribute macro that allows you to derive defaults.

Defaults are added to any Tup! macro by using the equals sign. #[tup_default] will then change the invocation so that it is a part of the type information itself. As such #[tup_default] needs to be used on any item that uses defaults in a Tup! invocation. Since a defaulted Tup is a type TupInto must be used to convert it.

#[tup_default]
pub fn main() {
    let default: Tup!(foo: i32 = 2) = tup!().into_tup();
    let result = default_to_non(tup!().into_tup());

    assert_eq!(result, tup!(foo: 2));
    assert_eq!(result.foo, default.foo);
}
#[tup_default]
fn default_to_non(n_tup: Tup!(foo: i32 = 2)) -> Tup!(foo: i32) {
    n_tup.into_tup()
}