use std::marker::PhantomData;
use crate::Context;
use crate::context::SlotId;
pub struct CellHandle<T> {
pub(crate) id: SlotId,
pub(crate) _marker: PhantomData<T>,
}
impl<T> CellHandle<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_cell(self)
}
pub fn set(&self, ctx: &Context, value: T)
where
T: PartialEq + 'static,
{
ctx.set_cell(self, value);
}
pub fn clear_dependents(&self, ctx: &Context) {
ctx.clear_cell_dependents(self.id);
}
}
impl<T> Clone for CellHandle<T> {
fn clone(&self) -> Self {
*self
}
}
impl<T> Copy for CellHandle<T> {}