pub struct Behavior<T> { /* private fields */ }Expand description
A time-varying value backed by geometric algebra
Behavior<T> wraps any value type T and stores it internally as a
GA3 multivector. This enables:
- Reactive updates with subscriber notification
- Derived behaviors via
mapandcombine - Geometric transformations under the hood
§Example
use cliffy_core::{behavior, Behavior};
let count = behavior(0);
assert_eq!(count.sample(), 0);
count.update(|n| n + 1);
assert_eq!(count.sample(), 1);Implementations§
Source§impl<T: IntoGeometric + FromGeometric + Clone + 'static> Behavior<T>
impl<T: IntoGeometric + FromGeometric + Clone + 'static> Behavior<T>
Sourcepub fn update<F>(&self, f: F)where
F: FnOnce(T) -> T,
pub fn update<F>(&self, f: F)where
F: FnOnce(T) -> T,
Update the value using a transformation function
The function receives the current value and returns the new value. All subscribers are notified after the update.
Sourcepub fn subscribe<F>(&self, callback: F) -> Subscription
pub fn subscribe<F>(&self, callback: F) -> Subscription
Subscribe to value changes
Returns a Subscription that can be used to unsubscribe.
Sourcepub fn map<U, F>(&self, f: F) -> Behavior<U>
pub fn map<U, F>(&self, f: F) -> Behavior<U>
Create a derived behavior by mapping a function over this behavior
The derived behavior will automatically update when this behavior changes.
Sourcepub fn combine<U, V, F>(&self, other: &Behavior<U>, f: F) -> Behavior<V>where
U: IntoGeometric + FromGeometric + Clone + 'static,
V: IntoGeometric + FromGeometric + Clone + 'static,
F: Fn(T, U) -> V + Clone + 'static,
pub fn combine<U, V, F>(&self, other: &Behavior<U>, f: F) -> Behavior<V>where
U: IntoGeometric + FromGeometric + Clone + 'static,
V: IntoGeometric + FromGeometric + Clone + 'static,
F: Fn(T, U) -> V + Clone + 'static,
Combine two behaviors into a new behavior
Sourcepub fn geometric_state(&self) -> GA3
pub fn geometric_state(&self) -> GA3
Get the internal geometric state (for advanced users)
Sourcepub fn apply_geometric<F>(&self, transform: F)
pub fn apply_geometric<F>(&self, transform: F)
Apply a geometric transformation directly (for advanced users)
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for Behavior<T>
impl<T> !RefUnwindSafe for Behavior<T>
impl<T> !Send for Behavior<T>
impl<T> !Sync for Behavior<T>
impl<T> Unpin for Behavior<T>
impl<T> UnsafeUnpin for Behavior<T>
impl<T> !UnwindSafe for Behavior<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