I admit up front, my question here is not very clear. In part, I am not sure what I am asking, and in part, I may be abstracting too much.
I have a piece of code that looks like this:
pub struct Func1<T0> {
i0: Rc<RefCell<T0>>,
func: Box<dyn Fn(T0) -> u64>,
}
pub struct Func2<T0, T1> {
i0: Rc<RefCell<T0>>,
i1: Rc<RefCell<T1>>,
func: Box<dyn Fn(T0, T1) -> u64>,
}
pub struct Func3<T0, T1, T2> {
i0: Rc<RefCell<T0>>,
i1: Rc<RefCell<T1>>,
i2: Rc<RefCell<T2>>,
func: Box<dyn Fn(T0, T1, T2) -> u64>,
}
pub struct Func4<T0, T1, T2, T3> {
i0: Rc<RefCell<T0>>,
i1: Rc<RefCell<T1>>,
i2: Rc<RefCell<T2>>,
i3: Rc<RefCell<T3>>,
func: Box<dyn Fn(T0, T1, T2, T3) -> u64>,
}
I am trying to figure out if there is some way to abstract this via "heterogeneous list" ?
reason for "no": It is not uncommon to see Rust code of the form:
Foo1<T0>;
Foo2<T0, T1>;
Foo3<T0, T1, T2>;
...
reason for "yes"; it seems, in pseudocode, all we want is:
pub struct Foo<T: HList> {
inputs: type_map (T, x -> Rc<RefCell<x>>),
func: Box<dyn Fn(parts of T) -> u64>
}
Apologies in advance for the vaguely / confusingly formulated question. Part of the problem is that I'm not sure I have the right framework to frame this question.