Hello,
These "no" cases are the functionality of the API that I would like to accomplish.
fn main() {
let op = B { op: Box::new(|_| {}) };
let mut u = U {};
let mut v = V {};
for _ in 0..10 {
// (op.op)(&mut u); // yes
// (op.op)(&mut v); // yes
// (op.op)(&mut (&u, &v)); // no
// struct UV<'a> { // no
// u: &'a mut U,
// v: &'a mut V
// }
// (op.op)(&mut UV {u: &mut u, v: &mut v});
}
}
struct U;
struct V;
struct B<T> {
op: Box<dyn Fn(&mut T)>
}
My understanding is that in both the "no" cases the generic T in B is resolving to a single lifetime like B<T<'a>> & to the compiler it looks as if B will store T<'a>.
What are my options to move forward?
Is there a way to allow the users of the API to bundle & pass whatever mutable state they want to?
Thank you for your help in advance!