use std::marker::PhantomData;
use crate::Context;
use crate::context::SlotId;
pub struct SlotHandle<T> {
pub(crate) id: SlotId,
pub(crate) _marker: PhantomData<T>,
}
impl<T> SlotHandle<T> {
pub(crate) fn new(id: SlotId) -> Self {
Self {
id,
_marker: PhantomData,
}
}
pub fn get(&self, ctx: &Context) -> T
where
T: Clone + 'static,
{
ctx.get(self)
}
pub fn clear(&self, ctx: &Context) {
ctx.clear_slot(self.id);
ctx.flush_effects_after_invalidation();
}
}
impl<T> Clone for SlotHandle<T> {
fn clone(&self) -> Self {
*self
}
}
impl<T> Copy for SlotHandle<T> {}