memoize
memoize copied to clipboard
`SharedCache` option causes compilation error
Hi @dermesser, thank you for this super useful crate! I'm trying to use the SharedCache
option like so:
#[memoize(SharedCache)
fn my_function(arg: &'static str) -> Result<Struct, Error> {
/// ...
}
But when I try to compile this I get:
$ cargo test --features=all
Compiling ha-ndarray v0.2.0 (/.../ha-ndarray)
error[E0599]: no method named `with` found for struct `MEMOIZED_MAPPING_READ_SLICE` in the current scope
--> src/opencl/programs/slice.rs:65:1
|
65 | #[memoize(SharedCache, Capacity: 1024)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| method `with` not found for this struct
| method not found in `MEMOIZED_MAPPING_READ_SLICE`
This is on version 0.4.1. Do you have any ideas about what might be going on?
use memoize::memoize;
#[derive(Clone)]
struct Struct {}
#[derive(Clone)]
struct Error {}
#[memoize(SharedCache, Capacity: 1024)]
fn my_function(arg: &'static str) -> Result<Struct, Error> {
println!("{}", arg);
Ok(Struct{})
}
fn main() {
let s = "Hello World";
my_function(s).ok();
}
I tried this, and it works:
$ cargo run --example issue30
Compiling memoize v0.4.1 (/home/lbo/dev/rust/memoize)
Finished dev [unoptimized + debuginfo] target(s) in 0.17s
Running `target/debug/examples/issue30`
Hello World
I notice that the symbol which can't be found is upper-cased, but I think current versions use a lower-case version. Can you double check the versions maybe? Otherwise I don't know much right now
I'm definitely using memoize version 0.4.1 with rustc version 1.74.0. Here's the version tree for memoize in case it's helpful:
memoize v0.4.1
│ ├── lazy_static v1.4.0
│ ├── lru v0.7.8
│ │ └── hashbrown v0.12.3
│ │ └── ahash v0.7.7
│ │ ├── getrandom v0.2.11
│ │ │ ├── cfg-if v1.0.0
│ │ │ └── libc v0.2.150
│ │ └── once_cell v1.18.0
│ │ [build-dependencies]
│ │ └── version_check v0.9.4
│ └── memoize-inner v0.4.0 (proc-macro)
│ ├── lazy_static v1.4.0
│ ├── proc-macro2 v1.0.70
│ │ └── unicode-ident v1.0.12
│ ├── quote v1.0.33
│ │ └── proc-macro2 v1.0.70 (*)
│ └── syn v1.0.109
│ ├── proc-macro2 v1.0.70 (*)
│ ├── quote v1.0.33 (*)
│ └── unicode-ident v1.0.12
I'm reporting the same issue on a new project with only memoize and the sample code provided above, both with nightly 1.76.0 and stable 1.74.0.
Here's my version tree:
memoizetest v0.1.0
└── memoize v0.4.1
├── lazy_static v1.4.0
├── lru v0.7.8
│ └── hashbrown v0.12.3
│ └── ahash v0.7.7
│ ├── getrandom v0.2.11
│ │ └── cfg-if v1.0.0
│ └── once_cell v1.19.0
│ [build-dependencies]
│ └── version_check v0.9.4
└── memoize-inner v0.4.0 (proc-macro)
├── lazy_static v1.4.0
├── proc-macro2 v1.0.70
│ └── unicode-ident v1.0.12
├── quote v1.0.33
│ └── proc-macro2 v1.0.70 (*)
└── syn v1.0.109
├── proc-macro2 v1.0.70 (*)
├── quote v1.0.33 (*)
└── unicode-ident v1.0.12
Same issue here, turning on SharedCache
results in a compile error. Here's my code in case more test cases are needed (spoilers for this year's Advent of Code day 12, if anyone is participating):
https://github.com/ericswpark/advent-of-code-solutions/blob/69696240b63faede3016dfb9f55afa3ab29a1e32/2023/day-12/src/main.rs#L122
I also ran into this issue while trying to solve Advent of Code Day 12. I tried building with stable 1.74.0 and 1.74.1, and nightly 1.76.
Here's my code, although fair warning it's a bit of a mess.
https://github.com/WillLillis/advent_of_code/blob/52b27533f90130efefde39d52f8655c41093a5cc/advent_of_code_2023/day_12/part_2/src/main.rs#L154
EDIT: Pulling the crate from the github repo fixed the problem :)
cargo add --git https://github.com/dermesser/memoize memoize --features full