Derive Macro num_derive::FromPrimitive
source · #[derive(FromPrimitive)]
{
// Attributes available to this derive:
#[num_traits]
}
Expand description
Derives num_traits::FromPrimitive
for simple enums and newtypes.
§Examples
Simple enums can be derived:
#[derive(FromPrimitive)]
enum Color {
Red,
Blue,
Green = 42,
}
Enums that contain data are not allowed:
ⓘ
#[derive(FromPrimitive)]
enum Color {
Rgb(u8, u8, u8),
Hsv(u8, u8, u8),
}
Structs are not allowed:
ⓘ
#[derive(FromPrimitive)]
struct Color {
r: u8,
g: u8,
b: u8,
}