changeset 102:dc425adf42b3

Add an example that uses SharedCache This will catch the compile error on `cargo test`.
author Risto Saarelma <risto.saarelma@iki.fi>
date Fri, 04 Aug 2023 13:06:15 +0300
parents d691b841bed6
children e7d7a568411c
files examples/shared.rs
diffstat 1 files changed, 16 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/shared.rs	Fri Aug 04 13:06:15 2023 +0300
@@ -0,0 +1,16 @@
+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();
+}