use crate::api::stable;
pub fn stable_save<T>(t: T) -> Result<(), candid::Error>
where
T: candid::utils::ArgumentEncoder,
{
candid::write_args(&mut stable::StableWriter::default(), t)
}
pub fn stable_restore<T>() -> Result<T, String>
where
T: for<'de> candid::utils::ArgumentDecoder<'de>,
{
let bytes = stable::stable_bytes();
let mut de =
candid::de::IDLDeserialize::new(bytes.as_slice()).map_err(|e| format!("{:?}", e))?;
let res = candid::utils::ArgumentDecoder::decode(&mut de).map_err(|e| format!("{:?}", e))?;
Ok(res)
}