jaemk / cached

Rust cache structures and easy function memoization
MIT License
1.58k stars 96 forks source link

Add cached_key_result macro for caching success #3

Closed djmcgill closed 6 years ago

djmcgill commented 6 years ago

Hi, I recently came across the situation where I was trying to call a function which could fail. The function returned io::Result<Foo> which is not clonable because io::Error is not.

However Foo itself is so I made a macro that takes a function that returns a result and caches the success value. I only needed cached_key_result but if there's interest in including it I'll happily write cached_result.

jaemk commented 6 years ago

Thanks! I definitely overlooked Result returning functions.

Two things before I merge:

djmcgill commented 6 years ago

Okay, updated now. One thing that I didn't realise is that, because the cache type is different from the function result type, the cache type inference doesn't work and the type must always be specified.

jaemk commented 6 years ago

Thanks, looks good! There's just a couple things I commented on

djmcgill commented 6 years ago

Done

jaemk commented 6 years ago

Thanks! Looks like there's some issues compiling the example though. Maybe something funky got copy/pasted into the source file?

djmcgill commented 6 years ago

Seems fixed now! It was the indentation causing the problem

jaemk commented 6 years ago

Looks good! Thank you!