-
-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Add custom SendAnyMap for torin to not depend on freya-native-co…
…re (#1038) * fix: Add custom SendAnyMap for torin to not depend on freya-native-core always * clean up
- Loading branch information
Showing
8 changed files
with
69 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
use std::any::{ | ||
Any, | ||
TypeId, | ||
}; | ||
|
||
use rustc_hash::FxHashMap; | ||
|
||
/// A map of types that can be sent between threads | ||
#[derive(Debug)] | ||
pub struct SendAnyMap { | ||
map: FxHashMap<TypeId, Box<dyn Any + Send + Sync + 'static>>, | ||
} | ||
|
||
impl Default for SendAnyMap { | ||
fn default() -> Self { | ||
Self::new() | ||
} | ||
} | ||
|
||
impl SendAnyMap { | ||
pub fn new() -> Self { | ||
Self { | ||
map: FxHashMap::default(), | ||
} | ||
} | ||
|
||
pub fn get<T: 'static>(&self) -> Option<&T> { | ||
self.map | ||
.get(&TypeId::of::<T>()) | ||
.and_then(|any| any.downcast_ref::<T>()) | ||
} | ||
|
||
pub fn insert<T: Send + Sync + 'static>(&mut self, value: T) { | ||
self.map.insert(TypeId::of::<T>(), Box::new(value)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters