Documentation
use std::collections::HashSet;
use std::pin::Pin;
use std::sync::{Arc, Mutex};

pub struct EffectFn {
    closure: Pin<Box<dyn Fn() -> () + Send + Sync + 'static>>,
    pub deps_set: Mutex<Vec<Arc<Mutex<HashSet<Arc<EffectFn>>>>>>,
}
impl EffectFn {
    pub fn new<F>(closure: F) -> EffectFn
    where
        F: Fn() -> () + Send + Sync + 'static,
    {
        Self {
            closure: Box::pin(closure),
            deps_set: Mutex::new(vec![]),
        }
    }
    pub fn get_ptr_address(&self) -> usize {
        self as *const EffectFn as usize
    }
    pub fn run(&self) {
        (self.closure)()
    }
    pub fn on_track<I: crate::syn::rjson::json::Index + ToString + Clone>(&self, target_ptr: usize, index: &I) {
        log::trace!("track effect_fn: {}, target_ptr: {}, index: {}", self.get_ptr_address(), target_ptr, index.to_string());
    }
    pub fn on_trigger<I: crate::syn::rjson::json::Index + ToString + Clone>(&self, target_ptr: usize, index: &I) {
        log::trace!("trigger effect_fn: {}, target_ptr: {}, index: {}", self.get_ptr_address(), target_ptr, index.to_string());
    }
}
impl core::hash::Hash for EffectFn {
    fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
        self.get_ptr_address().hash(state);
    }
}
impl std::cmp::PartialEq for EffectFn {
    fn eq(&self, other: &Self) -> bool {
        self.get_ptr_address() == other.get_ptr_address()
    }
}
impl std::cmp::Eq for EffectFn {}