Skip to content

Commit

Permalink
Demo
Browse files Browse the repository at this point in the history
  • Loading branch information
ekr-cfa committed Oct 8, 2024
1 parent b941968 commit 7446766
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/people.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,24 @@ use std::{
use std::sync::Mutex;
use once_cell::sync::Lazy;

pub static mut DERIVED_DEPENDENCIES : Lazy<Mutex<HashMap<TypeId, Vec<TypeId>>>> = Lazy::new(|| {
pub static mut DERIVED_DEPENDENCIES : Lazy<Mutex<HashMap<TypeId, Vec<String>>>> = Lazy::new(|| {
Mutex::new(HashMap::new())
});

pub fn add_dependency<S: 'static, D: 'static>() {
unsafe {
let mut hm = DERIVED_DEPENDENCIES.lock().unwrap();
let dependencies = (*hm).entry(TypeId::of::<S>())
.or_insert_with(|| { Vec::<TypeId>::new() });
dependencies.push(TypeId::of::<D>());
.or_insert_with(|| { Vec::<String>::new() });
dependencies.push(String::from(std::any::type_name::<D>()));
}
}

pub fn get_dependencies<T: 'static>() -> Vec<TypeId> {
pub fn get_dependencies<T: 'static>() -> Vec<String> {
unsafe {
let mut hm = DERIVED_DEPENDENCIES.lock().unwrap();
let dependencies = (*hm).entry(TypeId::of::<T>())
.or_insert_with(|| { Vec::<TypeId>::new() });
.or_insert_with(|| { Vec::<String>::new()});
dependencies.clone()
}
}
Expand Down Expand Up @@ -151,7 +151,9 @@ macro_rules! define_derived_person_property {
paste! {
#[ctor]
fn [<$derived_property:snake _add_dep>]() {
$crate::people::add_dependency::<$derived_property, $derived_property>();
$(
$crate::people::add_dependency::<$dependency, $derived_property>();
)*
}
}
};
Expand Down

0 comments on commit 7446766

Please sign in to comment.