faucet_source_xml/serde_helpers.rs
1//! Serde helper modules for types that don't implement Serialize/Deserialize natively.
2
3/// Serialize/deserialize `reqwest::Method` as a string (e.g. `"GET"`, `"POST"`).
4pub mod http_method {
5 use serde::{Deserialize, Deserializer, Serializer};
6
7 pub fn serialize<S: Serializer>(method: &reqwest::Method, s: S) -> Result<S::Ok, S::Error> {
8 s.serialize_str(method.as_str())
9 }
10
11 pub fn deserialize<'de, D: Deserializer<'de>>(d: D) -> Result<reqwest::Method, D::Error> {
12 let s = String::deserialize(d)?;
13 s.parse().map_err(serde::de::Error::custom)
14 }
15}