ShallowObserver

Struct ShallowObserver 

Source
pub struct ShallowObserver<'i, T> { /* private fields */ }
Expand description

A generic observer that only tracks complete replacements.

ShallowObserver provides a basic observer implementation that treats any mutation through DerefMut as a complete replacement of the value. It does not track internal mutations, making it suitable for:

  1. Primitive types (numbers, booleans, etc.) that cannot be partially modified
  2. Types where internal mutation tracking is not needed
  3. External types that do not implement Observe

§Examples

Built-in implementation for primitive types:

use morphix::{Observe, Observer, JsonAdapter};

let mut value = 42i32;
let mut observer = value.observe();  // ShallowObserver<i32>
*observer = 43;  // Recorded as a complete replacement

Explicit usage via #[observe(shallow)] attribute:

use morphix::Observe;
use serde::Serialize;

// External type that doesn't implement Observe
#[derive(Serialize)]
struct External;

#[derive(Serialize, Observe)]
struct MyStruct {
    #[observe(shallow)]
    external: External,  // use ShallowObserver<External>
    normal: String,      // use StringObserver
}

§Type Parameters

  • 'i - lifetime of the observed value
  • T - type being observed

Implementations§

Source§

impl<'i, T> ShallowObserver<'i, T>

Source

pub fn new(value: &'i mut T) -> Self

Creates a new shallow observer for the given value.

§Arguments
  • value - value to observe

Trait Implementations§

Source§

impl<'i, T: Copy + Add<U>, U> Add<U> for ShallowObserver<'i, T>

Source§

type Output = <T as Add<U>>::Output

The resulting type after applying the + operator.
Source§

fn add(self, rhs: U) -> Self::Output

Performs the + operation. Read more
Source§

impl<'i, T: AddAssign<U>, U> AddAssign<U> for ShallowObserver<'i, T>

Source§

fn add_assign(&mut self, rhs: U)

Performs the += operation. Read more
Source§

impl<'i, T: Copy + BitAnd<U>, U> BitAnd<U> for ShallowObserver<'i, T>

Source§

type Output = <T as BitAnd<U>>::Output

The resulting type after applying the & operator.
Source§

fn bitand(self, rhs: U) -> Self::Output

Performs the & operation. Read more
Source§

impl<'i, T: BitAndAssign<U>, U> BitAndAssign<U> for ShallowObserver<'i, T>

Source§

fn bitand_assign(&mut self, rhs: U)

Performs the &= operation. Read more
Source§

impl<'i, T: Copy + BitOr<U>, U> BitOr<U> for ShallowObserver<'i, T>

Source§

type Output = <T as BitOr<U>>::Output

The resulting type after applying the | operator.
Source§

fn bitor(self, rhs: U) -> Self::Output

Performs the | operation. Read more
Source§

impl<'i, T: BitOrAssign<U>, U> BitOrAssign<U> for ShallowObserver<'i, T>

Source§

fn bitor_assign(&mut self, rhs: U)

Performs the |= operation. Read more
Source§

impl<'i, T: Copy + BitXor<U>, U> BitXor<U> for ShallowObserver<'i, T>

Source§

type Output = <T as BitXor<U>>::Output

The resulting type after applying the ^ operator.
Source§

fn bitxor(self, rhs: U) -> Self::Output

Performs the ^ operation. Read more
Source§

impl<'i, T: BitXorAssign<U>, U> BitXorAssign<U> for ShallowObserver<'i, T>

Source§

fn bitxor_assign(&mut self, rhs: U)

Performs the ^= operation. Read more
Source§

impl<'i, T> Deref for ShallowObserver<'i, T>

Source§

type Target = T

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<'i, T> DerefMut for ShallowObserver<'i, T>

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl<'i, T: Copy + Div<U>, U> Div<U> for ShallowObserver<'i, T>

Source§

type Output = <T as Div<U>>::Output

The resulting type after applying the / operator.
Source§

fn div(self, rhs: U) -> Self::Output

Performs the / operation. Read more
Source§

impl<'i, T: DivAssign<U>, U> DivAssign<U> for ShallowObserver<'i, T>

Source§

fn div_assign(&mut self, rhs: U)

Performs the /= operation. Read more
Source§

impl<'i, T: Index<U>, U> Index<U> for ShallowObserver<'i, T>

Source§

type Output = <T as Index<U>>::Output

The returned type after indexing.
Source§

fn index(&self, index: U) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<'i, T: IndexMut<U>, U> IndexMut<U> for ShallowObserver<'i, T>

Source§

fn index_mut(&mut self, index: U) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<'i, T: Copy + Mul<U>, U> Mul<U> for ShallowObserver<'i, T>

Source§

type Output = <T as Mul<U>>::Output

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: U) -> Self::Output

Performs the * operation. Read more
Source§

impl<'i, T: MulAssign<U>, U> MulAssign<U> for ShallowObserver<'i, T>

Source§

fn mul_assign(&mut self, rhs: U)

Performs the *= operation. Read more
Source§

impl<'i, T> Observer<'i, T> for ShallowObserver<'i, T>

Source§

fn observe(value: &'i mut T) -> Self

Creates a new observer for the given value. Read more
Source§

fn collect<A: Adapter>(this: Self) -> Result<Option<Mutation<A>>, A::Error>
where T: Serialize,

Collects all recorded mutations using the specified adapter. Read more
Source§

impl<'i, T: PartialEq<U>, U: ?Sized> PartialEq<U> for ShallowObserver<'i, T>

Source§

fn eq(&self, other: &U) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'i, T: PartialOrd<U>, U: ?Sized> PartialOrd<U> for ShallowObserver<'i, T>

Source§

fn partial_cmp(&self, other: &U) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<'i, T: Copy + Rem<U>, U> Rem<U> for ShallowObserver<'i, T>

Source§

type Output = <T as Rem<U>>::Output

The resulting type after applying the % operator.
Source§

fn rem(self, rhs: U) -> Self::Output

Performs the % operation. Read more
Source§

impl<'i, T: RemAssign<U>, U> RemAssign<U> for ShallowObserver<'i, T>

Source§

fn rem_assign(&mut self, rhs: U)

Performs the %= operation. Read more
Source§

impl<'i, T: Copy + Shl<U>, U> Shl<U> for ShallowObserver<'i, T>

Source§

type Output = <T as Shl<U>>::Output

The resulting type after applying the << operator.
Source§

fn shl(self, rhs: U) -> Self::Output

Performs the << operation. Read more
Source§

impl<'i, T: ShlAssign<U>, U> ShlAssign<U> for ShallowObserver<'i, T>

Source§

fn shl_assign(&mut self, rhs: U)

Performs the <<= operation. Read more
Source§

impl<'i, T: Copy + Shr<U>, U> Shr<U> for ShallowObserver<'i, T>

Source§

type Output = <T as Shr<U>>::Output

The resulting type after applying the >> operator.
Source§

fn shr(self, rhs: U) -> Self::Output

Performs the >> operation. Read more
Source§

impl<'i, T: ShrAssign<U>, U> ShrAssign<U> for ShallowObserver<'i, T>

Source§

fn shr_assign(&mut self, rhs: U)

Performs the >>= operation. Read more
Source§

impl<'i, T: Copy + Sub<U>, U> Sub<U> for ShallowObserver<'i, T>

Source§

type Output = <T as Sub<U>>::Output

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: U) -> Self::Output

Performs the - operation. Read more
Source§

impl<'i, T: SubAssign<U>, U> SubAssign<U> for ShallowObserver<'i, T>

Source§

fn sub_assign(&mut self, rhs: U)

Performs the -= operation. Read more

Auto Trait Implementations§

§

impl<'i, T> Freeze for ShallowObserver<'i, T>

§

impl<'i, T> RefUnwindSafe for ShallowObserver<'i, T>
where T: RefUnwindSafe,

§

impl<'i, T> !Send for ShallowObserver<'i, T>

§

impl<'i, T> !Sync for ShallowObserver<'i, T>

§

impl<'i, T> Unpin for ShallowObserver<'i, T>

§

impl<'i, T> !UnwindSafe for ShallowObserver<'i, T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.