1use facet::Facet;
6use facet_value::Value;
7
8#[expect(
18 clippy::unwrap_in_result,
19 reason = "the panicking step is encoding, which a Value this crate built cannot fail; only \
20 decoding into T, which cannot panic, can return the Err this signature promises"
21)]
22pub fn redecode<T: for<'a> Facet<'a>>(value: &Value) -> Result<T, facet_json::DeserializeError> {
23 #[expect(
24 clippy::expect_used,
25 reason = "a Value this crate itself built always encodes as JSON"
26 )]
27 let raw = facet_json::to_string(value).expect("a Value always encodes");
28 facet_json::from_str(&raw)
29}
30
31#[must_use]
38pub fn encode<'facet, T: Facet<'facet> + ?Sized>(body: &T) -> String {
39 #[expect(
40 clippy::expect_used,
41 reason = "request bodies are facet-derived plain fields or Values that always encode"
42 )]
43 facet_json::to_string(body).expect("a request body always encodes")
44}