#[derive(Default)]
pub struct QueryParams(Vec<(String, String)>);
impl QueryParams {
pub fn new() -> Self {
Self(Vec::new())
}
pub fn opt<T: ToString>(&mut self, key: &str, value: Option<&T>) -> &mut Self {
if let Some(v) = value {
self.0.push((key.to_string(), v.to_string()));
}
self
}
pub fn list<T: ToString>(&mut self, key: &str, value: Option<&Vec<T>>) -> &mut Self {
if let Some(items) = value {
if !items.is_empty() {
let joined = items
.iter()
.map(ToString::to_string)
.collect::<Vec<_>>()
.join(",");
self.0.push((key.to_string(), joined));
}
}
self
}
pub fn into_pairs(self) -> Vec<(String, String)> {
self.0
}
}