Mercurial > lbo > hg > memoize
changeset 78:e9ccc1702af0
Merge pull request #12 from Codadillo/master
Use a thread local cache for memoization.
author | Lewin Bormann <lbo@spheniscida.de> |
---|---|
date | Sat, 02 Apr 2022 13:51:05 -0700 |
parents | b493c1f99877 (diff) e010a33862ac (current diff) |
children | ff66cf5c7f8c |
files | |
diffstat | 2 files changed, 18 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/.github/workflows/test.yml Thu Mar 24 00:25:47 2022 -0700 +++ b/.github/workflows/test.yml Sat Apr 02 13:51:05 2022 -0700 @@ -6,6 +6,9 @@ build_and_test: name: Rust project runs-on: ubuntu-latest + strategy: + matrix: + features: ["--features=full", "--no-default-features"] steps: - uses: actions/checkout@v2 - uses: actions-rs/toolchain@v1 @@ -14,4 +17,4 @@ - uses: actions-rs/cargo@v1 with: command: test - args: --features full + args: ${{ matrix.features }}
--- a/examples/full_featured.rs Thu Mar 24 00:25:47 2022 -0700 +++ b/examples/full_featured.rs Sat Apr 02 13:51:05 2022 -0700 @@ -1,6 +1,6 @@ use memoize::memoize; -use std::time::{Instant, Duration}; use std::thread; +use std::time::{Duration, Instant}; #[derive(Debug, Clone)] struct ComplexStruct { @@ -9,6 +9,7 @@ i: Instant, } +#[cfg(feature = "full")] #[memoize(TimeToLive: Duration::from_secs(2), Capacity: 123)] fn hello(key: String) -> ComplexStruct { println!("hello: {}", key); @@ -20,13 +21,16 @@ } fn main() { - println!("result: {:?}", hello("ABC".to_string())); - println!("result: {:?}", hello("DEF".to_string())); - println!("result: {:?}", hello("ABC".to_string())); //Same as first - thread::sleep(core::time::Duration::from_millis(2100)); - println!("result: {:?}", hello("EFG".to_string())); - println!("result: {:?}", hello("ABC".to_string())); //Refreshed - println!("result: {:?}", hello("EFG".to_string())); //Same as first - println!("result: {:?}", hello("ABC".to_string())); //Same as refreshed - println!("result: {:?}", memoized_original_hello("ABC".to_string())); + #[cfg(feature = "full")] + { + println!("result: {:?}", hello("ABC".to_string())); + println!("result: {:?}", hello("DEF".to_string())); + println!("result: {:?}", hello("ABC".to_string())); //Same as first + thread::sleep(core::time::Duration::from_millis(2100)); + println!("result: {:?}", hello("EFG".to_string())); + println!("result: {:?}", hello("ABC".to_string())); //Refreshed + println!("result: {:?}", hello("EFG".to_string())); //Same as first + println!("result: {:?}", hello("ABC".to_string())); //Same as refreshed + println!("result: {:?}", memoized_original_hello("ABC".to_string())); + } }