/// Wraps the callback to the with given trait boundaries of the state.
///
/// Why there is unsafe?
/// * Given state is taken as dyn State we don't know the size. But rest assured it is sized.
/// * Executor of the callback should know what exactly coming up from state. That said it can even pass dynamically sized trait too, we can't constrain that.
/// * Cast it to the correct type and trust the boundaries which was already ensured at the method signature.
/// * Synchronization can't revolve around the unsafe. because we lock the dynamic state right after the cast.
Wraps the callback to the with given trait boundaries of the state.
Why there is unsafe.
Given state is taken as dyn State we don't know the size. But rest assured it is sized.
Executor of the callback should know what exactly coming up from state. That said it can even pass dynamically sized trait too, we can't constrain that.
Cast it to the correct type and trust the boundaries which was already ensured at the method signature.
Synchronization can't revolve around the unsafe. because we lock the dynamic state right after the cast.
Wraps the callback to the with given trait boundaries of the state . Why there is unsafe . Given state is taken as dyn State we don ' t know the size . But rest assured it is sized . Executor of the callback should know what exactly coming up from state . That said it can even pass dynamically sized trait too we can ' t constrain that . Cast it to the correct type and trust the boundaries which was already ensured at the method signature . Synchronization can ' t revolve around the unsafe . because we lock the dynamic state right after the cast .
fn wrap_callback<C, S>(&self, callback: C) -> Arc<dyn Fn(ProcState) + Send + Sync>
    where
        S: State + 'static,
        C: Fn(&mut S) + Send + Sync + 'static,
    {
        let wrapped = move |s: ProcState| {
            let x = unsafe { &*(&s as *const ProcState as *const Arc<Mutex<S>>) };
            let mut mg = x.lock().unwrap();
            callback(&mut *mg);
        };
        Arc::new(wrapped)
    }
fn wrap_callback < C , S > ( & self , callback : C ) -> Arc < dyn Fn ( ProcState ) + Send + Sync > where S : State + ' static , C : Fn ( & mut S ) + Send + Sync + ' static , { let wrapped = move | s : ProcState | { let x = unsafe { & * ( & s as * const ProcState as * const Arc < Mutex < S > > ) } ; let mut mg = x . lock ( ) . unwrap ( ) ; callback ( & mut * mg ) ; } ; Arc :: new ( wrapped ) }
Wraps the callback to the with given trait boundaries of the state.
Wraps the callback to the with given trait boundaries of the state .
&self
callback
C