Skip to main content

Behavior

Struct Behavior 

Source
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 map and combine
  • 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>

Source

pub fn new(initial: T) -> Self

Create a new behavior with an initial value

Source

pub fn sample(&self) -> T

Sample the current value

Source

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.

Source

pub fn set(&self, value: T)

Set the value directly

Source

pub fn subscribe<F>(&self, callback: F) -> Subscription
where F: Fn(&T) + 'static,

Subscribe to value changes

Returns a Subscription that can be used to unsubscribe.

Source

pub fn map<U, F>(&self, f: F) -> Behavior<U>
where U: IntoGeometric + FromGeometric + Clone + 'static, F: Fn(T) -> U + 'static,

Create a derived behavior by mapping a function over this behavior

The derived behavior will automatically update when this behavior changes.

Source

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

Source

pub fn geometric_state(&self) -> GA3

Get the internal geometric state (for advanced users)

Source

pub fn apply_geometric<F>(&self, transform: F)
where F: FnOnce(&GA3) -> GA3,

Apply a geometric transformation directly (for advanced users)

Trait Implementations§

Source§

impl<T> Clone for Behavior<T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

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> 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.