Source code
Revision control
Copy as Markdown
Other Tools
// This file is part of ICU4X. For terms of use, please see the file
// called LICENSE at the top level of the ICU4X source tree
/// Take a VarULE type and serialize it both in human and machine readable contexts,
/// and ensure it roundtrips correctly
///
/// Note that the concrete type may need to be explicitly specified to prevent issues with
#[cfg(feature = "serde")]
pub(crate) fn assert_serde_roundtrips<T>(var: &T)
where
T: crate::ule::VarULE + ?Sized + serde::Serialize,
for<'a> Box<T>: serde::Deserialize<'a>,
for<'a> &'a T: serde::Deserialize<'a>,
T: core::fmt::Debug + PartialEq,
{
let bincode = bincode::serialize(var).unwrap();
let deserialized: &T = bincode::deserialize(&bincode).unwrap();
let deserialized_box: Box<T> = bincode::deserialize(&bincode).unwrap();
assert_eq!(var, deserialized, "Single element roundtrips with bincode");
assert_eq!(
var, &*deserialized_box,
"Single element roundtrips with bincode"
);
let json = serde_json::to_string(var).unwrap();
let deserialized: Box<T> = serde_json::from_str(&json).unwrap();
assert_eq!(var, &*deserialized, "Single element roundtrips with serde");
}