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§

source§

impl<'a, T: SIMP, V> Shr<BySIMP<T>> for &'a BTreeMap<i64, V>

§

type Output = Option<&'a V>

The resulting type after applying the >> operator.
source§

fn shr(self, _rhs: BySIMP<T>) -> Self::Output

Performs the >> operation. Read more
source§

impl<'a, T: SIMP, V> Shr<BySIMP<T>> for &'a mut BTreeMap<i64, V>

§

type Output = Option<&'a mut V>

The resulting type after applying the >> operator.
source§

fn shr(self, _rhs: BySIMP<T>) -> Self::Output

Performs the >> operation. Read more

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.