In the following example we use a parametric type T to define a
generic enum type to represent colors. The possible levels of grey or
each color component (i.e.: red, green, blue) is stored as a value of the
specified type:
#[derive(Debug)]
enum Color<T> {
Grey(T),
Rgb(T, T, T),
}To use the Color<T> enum type, we must specify what is T:
let c1 = Color::<u8>::Grey(0xa0);
let c2 = Color::<u16>::Grey(0xff00);
let c3 = Color::<u8>::Rgb(0x00, 0xa0, 0x57);
(c1, c2, c3)(Grey(160), Grey(65280), Rgb(0, 160, 87))