const_default

Derive Macro ConstDefault

Source
#[derive(ConstDefault)]
{
    // Attributes available to this derive:
    #[const_default]
}
Available on crate feature derive only.
Expand description

Derives an implementation for the ConstDefault trait.

§Note

Currently only works with struct inputs.

§Example

§Struct

#[derive(ConstDefault)]
pub struct Color {
    r: u8,
    g: u8,
    b: u8,
}

assert_eq!(
    <Color as ConstDefault>::DEFAULT,
    Color { r: 0, g: 0, b: 0 },
)

§Tuple Struct

#[derive(ConstDefault)]
pub struct Vec3(f32, f32, f32);

assert_eq!(
    <Vec3 as ConstDefault>::DEFAULT,
    Vec3(0.0, 0.0, 0.0),
)