wled_json_api_library/structures/
palettes.rs

1use serde;
2use serde::{Serialize, Deserialize};
3use crate::errors::WledJsonApiError;
4
5
6#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
7#[serde(rename_all = "camelCase")]
8pub struct Palettes(Vec<String>);
9
10
11impl TryFrom<&str> for Palettes{
12    type Error = WledJsonApiError;
13    fn try_from(str_in: &str) -> Result<Palettes, WledJsonApiError> {
14        serde_json::from_str(str_in).map_err(|e| {WledJsonApiError::SerdeError(e)})
15    }
16}
17
18
19
20#[cfg(test)]
21mod tests {
22    use crate::structures::palettes::Palettes;
23
24    #[test]
25    fn it_works() {
26        let a: Palettes = Palettes::try_from
27            (r#"[
28"Default","* Random Cycle","* Color 1","* Colors 1&2","* Color Gradient","* Colors Only","Party","Cloud","Lava","Ocean",
29"Forest","Rainbow","Rainbow Bands","Sunset","Rivendell","Breeze","Red & Blue","Yellowout","Analogous","Splash",
30"Pastel","Sunset 2","Beach","Vintage","Departure","Landscape","Beech","Sherbet","Hult","Hult 64",
31"Drywet","Jul","Grintage","Rewhi","Tertiary","Fire","Icefire","Cyane","Light Pink","Autumn",
32"Magenta","Magred","Yelmag","Yelblu","Orange & Teal","Tiamat","April Night","Orangery","C9","Sakura",
33"Aurora","Atlantica","C9 2","C9 New","Temperature","Aurora 2","Retro Clown","Candy","Toxy Reaf","Fairy Reaf",
34"Semi Blue","Pink Candy","Red Reaf","Aqua Flash","Yelblu Hot","Lite Light","Red Flash","Blink Red","Red Shift","Red Tide",
35"Candy2"
36]"#).unwrap();
37        println!("{:?}", a);
38
39    }
40}
41