cached icon indicating copy to clipboard operation
cached copied to clipboard

How to aproach generics ?

Open big-lip-bob opened this issue 3 years ago • 4 comments

Since apparently i can't really use cached with generic functions (let's say fn add_one<T: One + Add<Output=T>>(n: T) -> T { n + T::one() }), how would i proceed to make a cache for a specific type that's valid as said generic (let's use usize) ?

big-lip-bob avatar Apr 16 '21 18:04 big-lip-bob

i am aware that i could specify the type, (as #[cached] fn add_one_usize(n: usize) -> usize { n + usize::one() }) (attempting at a macro now)

big-lip-bob avatar Apr 16 '21 19:04 big-lip-bob

@big-lip-bob did you ever resolve this?

tdudz avatar Jun 11 '21 02:06 tdudz

No, i left it dormant as i didn't have much time since then

big-lip-bob avatar Jun 11 '21 16:06 big-lip-bob

I ran into a similar issue and wrote the generic_singleton crate. It doesn't have any of the fancy macros cached has, mostly because it wasn't really aimed at writing a caching library, but there is no reason it cannot be done. Or perhaps even better, cached can use the generic_singleton crate to add the generic function caching feature :)

WalterSmuts avatar Sep 05 '22 08:09 WalterSmuts