freya_native_core/
lib.rs

1use std::any::{
2    Any,
3    TypeId,
4};
5
6use node_ref::NodeMask;
7
8pub mod attributes;
9pub mod dioxus;
10pub mod events;
11pub mod node;
12pub mod node_ref;
13mod passes;
14pub mod real_dom;
15pub mod tags;
16pub mod tree;
17
18use rustc_hash::FxHashMap;
19pub use shipyard::EntityId as NodeId;
20
21pub mod exports {
22    //! Important dependencies that are used by the rest of the library
23    //! Feel free to just add the dependencies in your own Crates.toml
24    // exported for the macro
25    #[doc(hidden)]
26    pub use rustc_hash::FxHashSet;
27    pub use shipyard;
28}
29
30/// A prelude of commonly used items
31pub mod prelude {
32    pub use crate::{
33        attributes::*,
34        dioxus::*,
35        events::*,
36        node::{
37            ElementNode,
38            FromAnyValue,
39            NodeType,
40            OwnedAttributeView,
41        },
42        node_ref::{
43            AttributeMaskBuilder,
44            NodeMaskBuilder,
45            NodeView,
46        },
47        passes::{
48            run_pass,
49            Dependancy,
50            DependancyView,
51            Dependants,
52            PassDirection,
53            RunPassView,
54            State,
55            TypeErasedState,
56        },
57        real_dom::{
58            NodeImmutable,
59            NodeMut,
60            NodeRef,
61            RealDom,
62        },
63        NodeId,
64        SendAnyMap,
65    };
66}
67
68/// A map of types that can be sent between threads
69#[derive(Debug)]
70pub struct SendAnyMap {
71    map: FxHashMap<TypeId, Box<dyn Any + Send + Sync + 'static>>,
72}
73
74impl Default for SendAnyMap {
75    fn default() -> Self {
76        Self::new()
77    }
78}
79
80impl SendAnyMap {
81    pub fn new() -> Self {
82        Self {
83            map: FxHashMap::default(),
84        }
85    }
86
87    pub fn get<T: 'static>(&self) -> Option<&T> {
88        self.map
89            .get(&TypeId::of::<T>())
90            .and_then(|any| any.downcast_ref::<T>())
91    }
92
93    pub fn insert<T: Send + Sync + 'static>(&mut self, value: T) {
94        self.map.insert(TypeId::of::<T>(), Box::new(value));
95    }
96}