memory: add `Send + Sync` reqirement, fix #337 (#341)

* memory: add `Send + Sync` reqirement, fix #337

* Update egui/src/memory.rs

Co-authored-by: Lucien Greathouse <me@lpghatguy.com>

Co-authored-by: Lucien Greathouse <me@lpghatguy.com>
This commit is contained in:
ilya sheprut 2021-04-30 14:03:45 +06:00 committed by GitHub
parent 02a62d1986
commit 101eed0d67
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 9 deletions

View File

@ -3,8 +3,8 @@ use std::fmt;
/// Like [`std::any::Any`], but also implements `Clone`.
pub(crate) struct AnyMapElement {
value: Box<dyn Any + 'static>,
clone_fn: fn(&Box<dyn Any + 'static>) -> Box<dyn Any + 'static>,
value: Box<dyn Any + 'static + Send + Sync>,
clone_fn: fn(&Box<dyn Any + 'static + Send + Sync>) -> Box<dyn Any + 'static + Send + Sync>,
}
impl fmt::Debug for AnyMapElement {
@ -24,9 +24,9 @@ impl Clone for AnyMapElement {
}
}
pub trait AnyMapTrait: 'static + Any + Clone {}
pub trait AnyMapTrait: 'static + Any + Clone + Send + Sync {}
impl<T: 'static + Any + Clone> AnyMapTrait for T {}
impl<T: 'static + Any + Clone + Send + Sync> AnyMapTrait for T {}
impl AnyMapElement {
pub(crate) fn new<T: AnyMapTrait>(t: T) -> Self {

View File

@ -8,10 +8,10 @@ pub(crate) struct AnyMapElement(AnyMapElementInner);
enum AnyMapElementInner {
Deserialized {
value: Box<dyn Any + 'static>,
clone_fn: fn(&Box<dyn Any + 'static>) -> Box<dyn Any + 'static>,
value: Box<dyn Any + 'static + Send + Sync>,
clone_fn: fn(&Box<dyn Any + 'static + Send + Sync>) -> Box<dyn Any + 'static + Send + Sync>,
serialize_fn: fn(&Box<dyn Any + 'static>) -> Result<String, ron::Error>,
serialize_fn: fn(&Box<dyn Any + 'static + Send + Sync>) -> Result<String, ron::Error>,
},
Serialized(String, TypeId),
}
@ -84,8 +84,14 @@ impl Clone for AnyMapElement {
}
}
pub trait AnyMapTrait: 'static + Any + Clone + Serialize + for<'a> Deserialize<'a> {}
impl<T: 'static + Any + Clone + Serialize + for<'a> Deserialize<'a>> AnyMapTrait for T {}
pub trait AnyMapTrait:
'static + Any + Clone + Serialize + for<'a> Deserialize<'a> + Send + Sync
{
}
impl<T: 'static + Any + Clone + Serialize + for<'a> Deserialize<'a> + Send + Sync> AnyMapTrait
for T
{
}
impl AnyMapElement {
pub(crate) fn new<T: AnyMapTrait>(t: T) -> Self {

View File

@ -500,3 +500,12 @@ impl Areas {
wants_to_be_on_top.clear();
}
}
// ----------------------------------------------------------------------------
#[cfg(test)]
#[test]
fn memory_impl_send_sync() {
fn assert_send_sync<T: Send + Sync>() {}
assert_send_sync::<Memory>();
}