Skip to main content

cufflink_types/host/
mod.rs

1//! The envelopes of the host functions and the guest request, shared by
2//! the guest SDK and the platform so the two sides cannot drift.
3
4pub mod ext;
5pub mod http;
6pub mod nats;
7pub mod request;
8pub mod storage;
9pub mod wait;
10
11#[cfg(test)]
12pub(crate) mod tests {
13    use serde::de::DeserializeOwned;
14    use serde::Serialize;
15    use serde_json::Value;
16    use std::fmt::Debug;
17
18    pub(crate) fn round_trip<T: Serialize + DeserializeOwned + PartialEq + Debug>(
19        value: &T,
20        wire: Value,
21    ) {
22        assert_eq!(serde_json::to_value(value).expect("serialize"), wire);
23        assert_eq!(
24            &serde_json::from_value::<T>(wire).expect("deserialize"),
25            value
26        );
27    }
28
29    pub(crate) fn refused<T: DeserializeOwned + Debug>(wire: Value) {
30        let parsed = serde_json::from_value::<T>(wire.clone());
31        assert!(parsed.is_err(), "{wire} parsed as {parsed:?}");
32    }
33}