Mercurial > lbo > hg > memoize
view examples/shared.rs @ 106:bb57757a7727 default tip
Added tag v0.4.1 for changeset 793f2e38a318
author | Lewin Bormann <lbo@spheniscida.de> |
---|---|
date | Fri, 27 Oct 2023 20:22:19 +0200 |
parents | dc425adf42b3 |
children |
line wrap: on
line source
use memoize::memoize; #[memoize(SharedCache)] fn hello(arg: String, arg2: usize) -> bool { println!("{} => {}", arg, arg2); arg.len() % 2 == arg2 } fn main() { // `hello` is only called once here. assert!(!hello("World".to_string(), 0)); assert!(!hello("World".to_string(), 0)); // Sometimes one might need the original function. assert!(!memoized_original_hello("World".to_string(), 0)); memoized_flush_hello(); }