Add typemap that can be cloned and is Send + Sync
Signed-off-by: trivernis <trivernis@protonmail.com>main
parent
86ca6ce3e1
commit
b353b82e61
@ -0,0 +1,29 @@
|
||||
use crate::impl_typemap;
|
||||
use multi_trait_object::{MultitraitObject, RawClone, TryClone};
|
||||
use std::any::TypeId;
|
||||
use std::collections::HashMap;
|
||||
|
||||
impl_typemap!(
|
||||
/// A typemap that implements Clone and is Send + Sync
|
||||
CloneSendSyncTypeMap,
|
||||
CloneSendSyncTypeMapKey,
|
||||
RawClone,
|
||||
Send,
|
||||
Sync
|
||||
);
|
||||
|
||||
impl Clone for CloneSendSyncTypeMap {
|
||||
fn clone(&self) -> Self {
|
||||
let map = self
|
||||
.0
|
||||
.0
|
||||
.iter()
|
||||
.map(|(tid, mto)| (tid.clone(), mto.try_clone().unwrap()))
|
||||
.collect::<HashMap<TypeId, MultitraitObject>>();
|
||||
|
||||
Self(crate::type_indexed::TypeIndexedMap(map))
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl Send for CloneSendSyncTypeMap {}
|
||||
unsafe impl Sync for CloneSendSyncTypeMap {}
|
@ -1,7 +1,9 @@
|
||||
mod clone_send_sync_typemap;
|
||||
mod clone_typemap;
|
||||
mod partialeq_typemap;
|
||||
mod typemap;
|
||||
|
||||
pub use clone_send_sync_typemap::*;
|
||||
pub use clone_typemap::*;
|
||||
pub use partialeq_typemap::*;
|
||||
pub use typemap::*;
|
||||
|
Loading…
Reference in New Issue