cosmic::cosmic_theme::palette::serde::as_uint

Function deserialize

source
pub fn deserialize<'de, T, D>(
    deserializer: D,
) -> Result<T, <D as Deserializer<'de>>::Error>
where T: UintCast, <T as UintCast>::Uint: Deserialize<'de>, D: Deserializer<'de>,
Expand description

Deserialize a value from an unsigned integer.

use serde::Deserialize;
use palette::{Srgb, Srgba, rgb::{PackedArgb, PackedRgba}};

#[derive(Deserialize, PartialEq, Debug)]
struct MyColors {
    #[serde(deserialize_with = "palette::serde::deserialize_as_uint")]
    argb: PackedArgb,
    #[serde(deserialize_with = "palette::serde::deserialize_as_uint")]
    rgba: PackedRgba,
}

let my_colors = MyColors {
    argb: Srgb::new(0x17, 0xC6, 0x4C).into(),
    rgba: Srgba::new(0x17, 0xC6, 0x4C, 0xFF).into(),
};

let json = r#"{"argb":4279748172,"rgba":398871807}"#;
assert_eq!(
    serde_json::from_str::<MyColors>(json).unwrap(),
    my_colors
);