use std::marker::PhantomData;
use crate::Context;
use crate::context::SlotId;
pub trait EffectCallbackResult {
fn into_cleanup(self) -> Option<Box<dyn FnOnce()>>;
}
impl EffectCallbackResult for () {
fn into_cleanup(self) -> Option<Box<dyn FnOnce()>> {
None
}
}
impl<F> EffectCallbackResult for F
where
F: FnOnce() + 'static,
{
fn into_cleanup(self) -> Option<Box<dyn FnOnce()>> {
Some(Box::new(self))
}
}
pub struct EffectHandle {
pub(crate) id: SlotId,
pub(crate) _marker: PhantomData<()>,
}
impl EffectHandle {
pub(crate) fn new(id: SlotId) -> Self {
Self {
id,
_marker: PhantomData,
}
}
pub fn dispose(&self, ctx: &Context) {
ctx.dispose_effect(self);
}
pub fn is_active(&self, ctx: &Context) -> bool {
ctx.is_effect_active(self)
}
}
impl Clone for EffectHandle {
fn clone(&self) -> Self {
*self
}
}
impl Copy for EffectHandle {}