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:
- Primitive types (numbers, booleans, etc.) that cannot be partially modified
- Types where internal mutation tracking is not needed
- 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 replacementExplicit 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 valueT- type being observed
Implementations§
Trait Implementations§
Source§impl<'i, T: AddAssign<U>, U> AddAssign<U> for ShallowObserver<'i, T>
impl<'i, T: AddAssign<U>, U> AddAssign<U> for ShallowObserver<'i, T>
Source§fn add_assign(&mut self, rhs: U)
fn add_assign(&mut self, rhs: U)
Performs the
+= operation. Read moreSource§impl<'i, T: BitAndAssign<U>, U> BitAndAssign<U> for ShallowObserver<'i, T>
impl<'i, T: BitAndAssign<U>, U> BitAndAssign<U> for ShallowObserver<'i, T>
Source§fn bitand_assign(&mut self, rhs: U)
fn bitand_assign(&mut self, rhs: U)
Performs the
&= operation. Read moreSource§impl<'i, T: BitOrAssign<U>, U> BitOrAssign<U> for ShallowObserver<'i, T>
impl<'i, T: BitOrAssign<U>, U> BitOrAssign<U> for ShallowObserver<'i, T>
Source§fn bitor_assign(&mut self, rhs: U)
fn bitor_assign(&mut self, rhs: U)
Performs the
|= operation. Read moreSource§impl<'i, T: BitXorAssign<U>, U> BitXorAssign<U> for ShallowObserver<'i, T>
impl<'i, T: BitXorAssign<U>, U> BitXorAssign<U> for ShallowObserver<'i, T>
Source§fn bitxor_assign(&mut self, rhs: U)
fn bitxor_assign(&mut self, rhs: U)
Performs the
^= operation. Read moreSource§impl<'i, T> Deref for ShallowObserver<'i, T>
impl<'i, T> Deref for ShallowObserver<'i, T>
Source§impl<'i, T> DerefMut for ShallowObserver<'i, T>
impl<'i, T> DerefMut for ShallowObserver<'i, T>
Source§impl<'i, T: DivAssign<U>, U> DivAssign<U> for ShallowObserver<'i, T>
impl<'i, T: DivAssign<U>, U> DivAssign<U> for ShallowObserver<'i, T>
Source§fn div_assign(&mut self, rhs: U)
fn div_assign(&mut self, rhs: U)
Performs the
/= operation. Read moreSource§impl<'i, T: Index<U>, U> Index<U> for ShallowObserver<'i, T>
impl<'i, T: Index<U>, U> Index<U> for ShallowObserver<'i, T>
Source§impl<'i, T: IndexMut<U>, U> IndexMut<U> for ShallowObserver<'i, T>
impl<'i, T: IndexMut<U>, U> IndexMut<U> for ShallowObserver<'i, T>
Source§impl<'i, T: MulAssign<U>, U> MulAssign<U> for ShallowObserver<'i, T>
impl<'i, T: MulAssign<U>, U> MulAssign<U> for ShallowObserver<'i, T>
Source§fn mul_assign(&mut self, rhs: U)
fn mul_assign(&mut self, rhs: U)
Performs the
*= operation. Read moreSource§impl<'i, T> Observer<'i, T> for ShallowObserver<'i, T>
impl<'i, T> Observer<'i, T> for ShallowObserver<'i, T>
Source§impl<'i, T: PartialOrd<U>, U: ?Sized> PartialOrd<U> for ShallowObserver<'i, T>
impl<'i, T: PartialOrd<U>, U: ?Sized> PartialOrd<U> for ShallowObserver<'i, T>
Source§impl<'i, T: RemAssign<U>, U> RemAssign<U> for ShallowObserver<'i, T>
impl<'i, T: RemAssign<U>, U> RemAssign<U> for ShallowObserver<'i, T>
Source§fn rem_assign(&mut self, rhs: U)
fn rem_assign(&mut self, rhs: U)
Performs the
%= operation. Read moreSource§impl<'i, T: ShlAssign<U>, U> ShlAssign<U> for ShallowObserver<'i, T>
impl<'i, T: ShlAssign<U>, U> ShlAssign<U> for ShallowObserver<'i, T>
Source§fn shl_assign(&mut self, rhs: U)
fn shl_assign(&mut self, rhs: U)
Performs the
<<= operation. Read moreSource§impl<'i, T: ShrAssign<U>, U> ShrAssign<U> for ShallowObserver<'i, T>
impl<'i, T: ShrAssign<U>, U> ShrAssign<U> for ShallowObserver<'i, T>
Source§fn shr_assign(&mut self, rhs: U)
fn shr_assign(&mut self, rhs: U)
Performs the
>>= operation. Read moreSource§impl<'i, T: SubAssign<U>, U> SubAssign<U> for ShallowObserver<'i, T>
impl<'i, T: SubAssign<U>, U> SubAssign<U> for ShallowObserver<'i, T>
Source§fn sub_assign(&mut self, rhs: U)
fn sub_assign(&mut self, rhs: U)
Performs the
-= operation. Read moreAuto 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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more