[][src]Derive Macro num_derive::ToPrimitive

#[derive(ToPrimitive)]

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:

This example deliberately fails to compile

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

Structs are not allowed:

This example deliberately fails to compile
#[derive(ToPrimitive)]
struct Color {
    r: u8,
    g: u8,
    b: u8,
}