/// Helpers for serializing to/deserializing from toml /// /// In order to use this module, set the "toml" feature in your Cargo.toml: /// /// ```toml,ignore /// [dependencies.elefren] /// version = "0.22" /// features = ["toml"] /// ``` pub mod toml; /// Helpers for serializing to/deserializing from json /// /// In order to use this module, set the "json" feature in your Cargo.toml: /// /// ```toml,ignore /// [dependencies.elefen] /// version = "0.22" /// features = ["json"] /// ``` pub mod json; /// Helpers for working with the command line pub mod cli; /// # Low-level API for extending // Convert the HTTP response body from JSON. Pass up deserialization errors // transparently. pub async fn deserialise_response serde::Deserialize<'de>>(response: reqwest::Response) -> crate::Result { let bytes = response.bytes().await?; match serde_json::from_slice(&bytes) { Ok(t) => { debug!("{}", String::from_utf8_lossy(&bytes)); Ok(t) } // If deserializing into the desired type fails try again to // see if this is an error response. Err(e) => { error!("{}", String::from_utf8_lossy(&bytes)); if let Ok(error) = serde_json::from_slice(&bytes) { return Err(crate::Error::Api(error)); } Err(e.into()) } } }