palette::cast

Function from_uint

source
pub fn from_uint<T>(uint: T::Uint) -> T
where T: UintCast,
Expand description

Cast from an unsigned integer to a color type.

use palette::{cast, rgb::PackedArgb, Srgba};

let color: PackedArgb = Srgba::new(0x17, 0xC6, 0x4C, 0xFF).into();
assert_eq!(cast::from_uint::<PackedArgb>(0xFF17C64C), color);

It’s also possible to use From and Into when casting built-in types:

use palette::Srgba;

let uint = 0xFF17C64C;

// Integers implement `Into`:
let color1: Srgba<u8> = uint.into();

// Colors implement `From`:
let color2 = Srgba::from(uint);