Derive Macro num_derive::ToPrimitive

source ·
#[derive(ToPrimitive)]
{
    // Attributes available to this derive:
    #[num_traits]
}
Expand description

Derives num_traits::ToPrimitive for simple enums and newtypes.

§Examples

Simple enums can be derived:


#[derive(ToPrimitive)]
enum Color {
    Red,
    Blue,
    Green = 42,
}

Enums that contain data are not allowed:


#[derive(ToPrimitive)]
enum Color {
    Rgb(u8, u8, u8),
    Hsv(u8, u8, u8),
}

Structs are not allowed:

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