Skip to main content

Module observable

Module observable 

Source
Expand description

Observable value wrapper with change notification and version tracking.

§Design

Observable<T> wraps a value of type T in shared, reference-counted storage (Rc<RefCell<..>>). When the value changes (determined by PartialEq), all live subscribers are notified in registration order.

§Performance

OperationComplexity
get()O(1)
set()O(S) where S = subscribers
subscribe()O(1) amortized
Memory~48 bytes + sizeof(T)

§Failure Modes

  • Re-entrant set: Calling set() from within a subscriber callback will panic (RefCell borrow rules). This is intentional: re-entrant mutations indicate a design bug in the subscriber graph.
  • Subscriber leak: If Subscription guards are stored indefinitely without being dropped, callbacks accumulate. Dead weak references are cleaned lazily during notify().

Structs§

Observable
A shared, version-tracked value with change notification.
Subscription
RAII guard for a subscriber callback.