use crate::error::{Error, Result};
pub trait Operation {
type Output: serde::de::DeserializeOwned;
const METHOD: http::Method;
fn path(&self) -> String;
fn query(&self) -> Vec<(&'static str, String)> {
Vec::new()
}
fn headers(&self) -> Vec<(&'static str, String)> {
Vec::new()
}
fn body(&self) -> Result<Option<Vec<u8>>> {
Ok(None)
}
}
pub fn json_body<T: serde::Serialize>(value: &T) -> Result<Option<Vec<u8>>> {
serde_json::to_vec(value).map(Some).map_err(Error::encode)
}
pub fn push_opt<T: ToString>(
q: &mut Vec<(&'static str, String)>,
key: &'static str,
value: Option<T>,
) {
if let Some(v) = value {
q.push((key, v.to_string()));
}
}