use crate::Mode;
pub trait Inject {
type Primitive;
fn new(mode: Mode, value: Self::Primitive) -> Self;
fn constant(value: Self::Primitive) -> Self
where
Self: Sized,
{
Self::new(Mode::Constant, value)
}
}
impl<C0: Eq + core::hash::Hash + Inject<Primitive = P0>, C1: Inject<Primitive = P1>, P0, P1> Inject
for indexmap::IndexMap<C0, C1>
{
type Primitive = indexmap::IndexMap<P0, P1>;
#[inline]
fn new(mode: Mode, value: Self::Primitive) -> Self {
value.into_iter().map(|(v0, v1)| (C0::new(mode, v0), C1::new(mode, v1))).collect()
}
}
impl<C: Inject<Primitive = P>, P> Inject for Vec<C> {
type Primitive = Vec<P>;
#[inline]
fn new(mode: Mode, value: Self::Primitive) -> Self {
value.into_iter().map(|v| C::new(mode, v)).collect()
}
}
macro_rules! inject_tuple {
(($t0:ident, 0), $(($ty:ident, $idx:tt)),*) => {
impl<$t0: Inject, $($ty: Inject),*> Inject for ($t0, $($ty),*) {
type Primitive = ($t0::Primitive, $( $ty::Primitive ),*);
#[inline]
fn new(mode: Mode, value: Self::Primitive) -> Self {
($t0::new(mode, value.0), $($ty::new(mode, value.$idx)),*)
}
}
}
}
inject_tuple!((C0, 0), (C1, 1));
inject_tuple!((C0, 0), (C1, 1), (C2, 2));
inject_tuple!((C0, 0), (C1, 1), (C2, 2), (C3, 3));
inject_tuple!((C0, 0), (C1, 1), (C2, 2), (C3, 3), (C4, 4));