use crate::prelude::*;
macro_rules! map {
($($k:expr => $v:expr),* $(,)?) => {{
let mut m = ::std::collections::BTreeMap::new();
$(m.insert($k, $v);)+
m
}};
}
pub(crate) use map;
pub trait TakeXImpl<T> {
fn take_x_impl(&mut self, k: &str) -> RustiumResult<Option<T>>;
}
pub trait TakeX {
fn take_x<T>(&mut self, k: &str) -> RustiumResult<Option<T>>
where
Self: TakeXImpl<T>;
fn take_x_val<T>(&mut self, k: &str) -> RustiumResult<T>
where
Self: TakeXImpl<T>;
}
impl<O> TakeX for O {
fn take_x<T>(&mut self, k: &str) -> RustiumResult<Option<T>>
where
Self: TakeXImpl<T>,
{
TakeXImpl::take_x_impl(self, k)
}
fn take_x_val<T>(&mut self, k: &str) -> RustiumResult<T>
where
Self: TakeXImpl<T>,
{
let val: Option<T> = TakeXImpl::take_x_impl(self, k)?;
val.ok_or_else(|| RustiumError::PropertyNotFound(k.to_string()))
}
}