I'd like to share an evmap, a lock-free, eventually consistent, concurrent multi-value map, across all threads in a Rust program.
Naively, it would look like this:
#[macro_use]
extern crate lazy_static;
extern crate evmap;
use std::collections::hash_map::RandomState;
lazy_static! {
static ref MAP: (evmap::ReadHandle<u32, u32, (), RandomState>,
evmap::WriteHandle<u32, u32, (), RandomState>) = evmap::new();
}
fn main() {
println!("Hello, world!");
MAP.1.clear();
}
This gives:
error[E0277]: the trait bound `std::cell::Cell<()>: std::marker::Sync` is not satisfied in `(evmap::ReadHandle<u32, u32>, evmap::WriteHandle<u32, u32>)`
--> src/main.rs:8:1
|
8 | / lazy_static! {
9 | | static ref MAP: (evmap::ReadHandle<u32, u32, (), RandomState>,
10 | | evmap::WriteHandle<u32, u32, (), RandomState>) = evmap::new();
11 | | }
| |_^ `std::cell::Cell<()>` cannot be shared between threads safely
|
= help: within `(evmap::ReadHandle<u32, u32>, evmap::WriteHandle<u32, u32>)`, the trait `std::marker::Sync` is not implemented for `std::cell::Cell<()>`
= note: required because it appears within the type `std::marker::PhantomData<std::cell::Cell<()>>`
= note: required because it appears within the type `evmap::ReadHandle<u32, u32>`
= note: required because it appears within the type `(evmap::ReadHandle<u32, u32>, evmap::WriteHandle<u32, u32>)`
= note: required by `lazy_static::lazy::Lazy`
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
I think this is complaining about the ()
returned inside evmap::new()
:
pub fn new<K, V>(
) -> (ReadHandle<K, V, (), RandomState>, WriteHandle<K, V, (), RandomState>) where
K: Eq + Hash + Clone,
V: Eq + ShallowCopy,
Can it be done?