#[derive(Observe)]
{
// Attributes available to this derive:
#[observe]
}
Expand description
Derive the Observe trait for structs to enable mutation tracking.
This macro generates an observer type that wraps your struct and tracks mutations to its fields. The generated observer provides field-level mutation detection with support for nested structures.
§Requirements
- The struct must also derive or implement
Serialize - Only named structs are supported (not tuple structs or enums)
§Field Attributes
You can customize how individual fields are observed using the #[observe(...)] attribute:
#[observe(hash)]- Field will use HashObserver#[observe(noop)]- Field will use NoopObserver#[observe(shallow)]- Field will use ShallowObserver#[observe(snapshot)]- Field will use SnapshotObserver
§Example
use serde::Serialize;
use morphix::Observe;
#[derive(Serialize, Observe)]
struct User {
name: String, // StringObserver
age: i32, // SnapshotObserver<i32>
#[observe(noop)]
cache: String, // Not tracked
#[observe(shallow)]
metadata: Metadata, // ShallowObserver<Metadata>
}
#[derive(Serialize)]
struct Metadata {
created_at: String,
updated_at: String,
}