Struct sapio_base::simp::BySIMP
source · pub struct BySIMP<T>(pub PhantomData<T>);
Expand description
Trait Type Wrapper for Indexing with a SIMP.
Given a BTreeMap of SIMPs b, you can index it with the following syntax:
use sapio_base::simp::SIMP;
use serde_json::Value;
use sapio_base::simp::by_simp;
use sapio_base::simp::simp_value;
use std::collections::BTreeMap;
struct MySimp(Value);
impl SIMP for MySimp {
fn static_get_protocol_number() -> i64
where
Self: Sized,
{
1234
}
fn get_protocol_number(&self) -> i64 {
Self::static_get_protocol_number()
}
fn to_json(&self) -> Result<Value, serde_json::Error> {
Ok(self.0.clone())
}
fn from_json(value: Value) -> Result<Self, serde_json::Error>
where
Self: Sized,
{
Ok(Self(value))
}
}
let mut b : BTreeMap<i64, Box<dyn SIMP>> = BTreeMap::new();
b <<= Box::new(MySimp("Howdy".into()));
if let Some(simp) = &b >> by_simp::<MySimp>() {
} else {
panic!();
}
let mut c : BTreeMap<i64, Value> = BTreeMap::new();
c <<= simp_value(MySimp("Howdy 2".into()));
if let Some(simp) = &c >> by_simp::<MySimp>() {
} else {
panic!();
}
Tuple Fields§
§0: PhantomData<T>
Trait Implementations§
Auto Trait Implementations§
impl<T> RefUnwindSafe for BySIMP<T>where
T: RefUnwindSafe,
impl<T> Send for BySIMP<T>where
T: Send,
impl<T> Sync for BySIMP<T>where
T: Sync,
impl<T> Unpin for BySIMP<T>where
T: Unpin,
impl<T> UnwindSafe for BySIMP<T>where
T: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more