zaun_community_protocol/client/decode.rs
1//! Typed decoding of response bodies.
2
3use serde::de::DeserializeOwned;
4use serde_json::value::RawValue;
5
6use crate::command::Body;
7
8/// Decodes a successful response body as the response type of command `B`.
9///
10/// ```ignore
11/// let sent = decode_response::<message::Send>(&raw)?; // message::Sent
12/// ```
13///
14/// # Errors
15/// The body does not match `B::Response`.
16pub fn decode_response<B: Body>(body: &RawValue) -> serde_json::Result<B::Response>
17where
18 B::Response: DeserializeOwned,
19{
20 serde_json::from_str(body.get())
21}