I'd like to create a HashMap with lazy_static, but can't seem to provide the right type arguments:
use lazy_static::lazy_static;
use std::collections::HashMap;
use std::sync::Mutex;
lazy_static! {
static ref DROPPABLES: Mutex<HashMap<String, D: DroppableExt>> = Mutex::new(HashMap::new());
}
pub trait DroppableExt: DynClone+Send{
fn droppable_id(&self)->String;
}
gives error:
error[E0229]: associated type bindings are not allowed here
--> src\main.rs:56:54
|
56 | static ref NEW_DROPPABLES: Mutex<HashMap<String, D: DroppableExt>> = Mutex::new(HashMap::new()) ;
| ^^^^^^^^^^^^^^^ associated type not allowed here
What am I doing wrong here? I just want require that all the HashMap values have a type with implements DroppableExt.
Box<dyn DroppableExt>, if the dynamic dispatch and the inability to do anything not described by the trait suits you.lazy_static?