GeneralHandler

Trait GeneralHandler 

Source
pub trait GeneralHandler<T: ?Sized>: Default {
    type Spec;

    // Required methods
    fn on_observe(value: &mut T) -> Self;
    fn on_deref_mut(&mut self);
    fn on_collect(&self, value: &T) -> bool;
}
Expand description

A handler trait for implementing change detection strategies in GeneralObserver.

GeneralHandler defines the interface for pluggable change detection strategies used exclusively with GeneralObserver. Each handler implementation encapsulates a specific approach to detecting whether a value has changed.

§Lifecycle

§Example

A ShallowObserver implementation that treats any mutation through DerefMut as a complete replacement:

#[derive(Default)]
struct ShallowHandler {
    mutated: bool,
}

impl<T> GeneralHandler<T> for ShallowHandler {
    type Spec = DefaultSpec;

    fn on_observe(_value: &mut T) -> Self {
        Self { mutated: false }
    }

    fn on_deref_mut(&mut self) {
        self.mutated = true;
    }

    fn on_collect(&self, _value: &T) -> bool {
        self.mutated
    }
}

type ShallowObserver<'i, T> = GeneralObserver<'i, T, ShallowHandler>;

Required Associated Types§

Source

type Spec

Associated specification type for GeneralObserver.

Required Methods§

Source

fn on_observe(value: &mut T) -> Self

Called when observation begins.

Source

fn on_deref_mut(&mut self)

Called when the value is accessed through DerefMut.

Source

fn on_collect(&self, value: &T) -> bool

Called when collecting changes, returns whether a change occurred.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§