use std::marker::PhantomData;
use crate::general::{DebugHandler, GeneralHandler, GeneralObserver, ReplaceHandler};
use crate::helper::{AsDeref, Invalidate, Zero};
pub type ShallowObserver<'ob, S, D = Zero> = GeneralObserver<'ob, ShallowHandler<<S as AsDeref<D>>::Target>, S, D>;
pub struct ShallowHandler<T: ?Sized> {
mutated: bool,
phantom: PhantomData<T>,
}
impl<T: ?Sized> Invalidate<T> for ShallowHandler<T> {
fn invalidate(&mut self, _: &T) {
self.mutated = true;
}
}
impl<T: ?Sized> GeneralHandler for ShallowHandler<T> {
type Target = T;
fn observe(_value: &T) -> Self {
Self {
mutated: false,
phantom: PhantomData,
}
}
}
impl<T: ?Sized> ReplaceHandler for ShallowHandler<T> {
fn is_replace(&self, _value: &T) -> bool {
self.mutated
}
}
impl<T: ?Sized> DebugHandler for ShallowHandler<T> {
const NAME: &'static str = "ShallowObserver";
}