diff --git a/src/function_manager.rs b/src/function_manager.rs index 85f8155..4bcd0d8 100644 --- a/src/function_manager.rs +++ b/src/function_manager.rs @@ -9,6 +9,8 @@ use std::hash::{Hash, Hasher}; use std::ops::BitXorAssign; type Functions = Vec<(Id, FunctionEntry)>; + +#[derive(Serialize, Deserialize)] pub struct FunctionManager { functions: Functions, } @@ -17,45 +19,26 @@ impl Default for FunctionManager { fn default() -> Self { let mut vec: Functions = Vec::with_capacity(COLORS.len()); vec.push(( - Id::new(11414819524356497634_u64), // Random number here to avoid call to crate::misc::random_u64() + Id::new("Function Manager"), FunctionEntry::default(), )); Self { functions: vec } } } -impl Serialize for FunctionManager { - fn serialize(&self, serializer: S) -> Result - where - S: Serializer, - { - let mut s = serializer.serialize_struct("FunctionManager", 1)?; - s.serialize_field( - "data", - &self - .functions - .iter() - .map(|(id, func)| (*id, func.clone())) - .collect::>(), - )?; - s.end() - } -} +#[test] +fn func_manager_roundtrip_serdes() { + let mut func_manager = FunctionManager { + functions: Vec::new(), + }; -impl<'de> Deserialize<'de> for FunctionManager { - fn deserialize(deserializer: D) -> Result - where - D: Deserializer<'de>, - { - #[derive(Deserialize)] - struct Helper(Vec<(Id, FunctionEntry)>); - - let helper = Helper::deserialize(deserializer)?; - - Ok(FunctionManager { - functions: helper.0.to_vec(), - }) - } + func_manager.push_empty(); + let ser = bincode::serialize(&func_manager).expect("unable to serialize"); + let des: FunctionManager = bincode::deserialize(&ser).expect("unable to deserialize"); + assert_eq!( + func_manager.functions[0].1.raw_func_str, + des.functions[0].1.raw_func_str + ); } /// Function that creates button that's used with the `button_area`