4 ms·
> While solving a not-so-easy lifetime problem in Rust related to async closures, The problem is async not the borrow checker. Async adds a lot of incidental c
by RcouF1uZ4gsC 4y ago
> While solving a not-so-easy lifetime problem in Rust related to async closures,
The problem is async not the borrow checker. Async adds a lot of incidental complexity
- barefeg 4y agoIs there any way around it?
- mrkeen 4y agoI experienced similar headaches without async code. I always need helper functions to let me open a file and work with the contents. It seems like I always need new variants depending on what operations I'll do inside 'f', e.g: pub fn with_vec_align<A,V>(file_name: &str, f: &dyn Fn(&[V]) -> A) -> A pub fn with_vec_align_mut<A,V>(file_name: &str, f: &mut dyn FnMut(&[V]) -> A) -> A pub fn with_vec<A>(file_name: &str, f: &dyn Fn(&[u8]) -> A) -> A fn with_vec_mut<A>(file_name: &str, f: &mut dyn FnMut(&[u8]) -> A) -> A pub fn with_mut_vec<A, V>(file_name: &str, f: &dyn Fn(&mut [V]) -> A) -> A It's the kind of thing I'd hope polymorphism would solve (maybe it already does but I just don't know how to leverage it).