Mercurial > lbo > hg > memoize
view examples/trivial.rs @ 69:0ada62444b37
Merge pull request #10 from bijij/master
Add support for pattern binding to function arguments
author | Lewin Bormann <lbo@spheniscida.de> |
---|---|
date | Sat, 01 Jan 2022 12:29:34 +0100 |
parents | 3ed9875b9139 |
children | 868eb5c58450 |
line wrap: on
line source
use memoize::memoize; #[memoize] 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)); }