3 ms·
I 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 ne
by mrkeen 4y ago
I 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).