Skip to main content

Property

Struct Property 

Source
pub struct Property<T> { /* private fields */ }
Expand description

Thread-safe application state with snapshot reads and atomic publication.

Clones share the value, including when moved into a worker or Tokio task. Reading never evaluates a UI expression. Use Self::local inside an entered super::PropertyGraph to connect to owner-thread computations. A write publishes immediately; attached graphs observe it on their next import. Intermediate revisions may coalesce. Use a channel for events that must each be delivered.

Implementations§

Source§

impl<T: SharedPropertyValue> Property<T>

Source

pub fn new(value: T) -> Self

Creates independent shared state. No UI thread or graph is required.

Source

pub fn published(&self) -> Published<T>

Export read-only shared snapshots, including owner-thread computed output.

Source

pub fn get(&self) -> T

Returns a clone of the latest published value on any thread.

Source

pub fn read<R>(&self, f: impl FnOnce(&T) -> R) -> R

Reads an immutable snapshot without holding a storage lock during f. Reentrant reads and writes are permitted here.

Source

pub fn observed_revision(&self) -> Option<u64>

Revision imported or published by this thread’s entered UI graph. Returns None if this property has no active attachment in that graph. This diagnostic never imports data or evaluates a computation.

Source

pub fn set(&self, value: T)

Atomically publishes a value and requests work from attached graphs.

Source

pub fn update(&self, f: impl FnOnce(&mut T))

Updates one property atomically, invoking f exactly once.

The closure edits a private draft. A panic leaves the published value unchanged. Neither this closure nor value cloning/equality invoked during mutation may recursively mutate a property; this is diagnosed with a panic before acquiring another write lock. Snapshot reads are allowed. Keep callbacks short and never wait for a worker or UI task.

Source

pub fn set_if_neq(&self, value: T) -> bool
where T: PartialEq,

Compares and publishes under the same single-property write operation.

Source

pub fn revision(&self) -> u64

Monotonic revision of the currently published value.

Source

pub fn local(&self) -> LocalProperty<T>

Obtains this graph’s local view of the shared value.

Requires an entered super::PropertyGraph. The view participates in lazy computation and two-way binding on its owner thread. Worker writes become visible to the view when that graph imports publications.

Source

pub fn untyped(&self) -> UntypedProperty

Returns a local dependency handle. This handle cannot cross threads.

Source

pub fn replace_with(&self, source: LocalProperty<T>)

Installs an owner-thread binding while retaining this shared identity.

Trait Implementations§

Source§

impl<T> Clone for Property<T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<T: SharedPropertyValue + Debug> Debug for Property<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: SharedPropertyValue> Default for Property<T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de, T: SharedPropertyValue + Deserialize<'de>> Deserialize<'de> for Property<T>

Source§

fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<T: SharedPropertyValue> Interpolatable for Property<T>

Source§

fn interpolate(&self, other: &Self, t: f64) -> Self

Interpolates this value toward other at time t on the unit interval. Read more
Source§

impl<T: SharedPropertyValue> PropertyBinding<T> for Property<T>

Source§

fn from_value(value: T) -> Self

Creates independent literal state of this field’s ownership kind.
Source§

fn local(&self) -> LocalProperty<T>

Obtains the owner-thread view used by generated bindings.
Source§

fn from_local(source: LocalProperty<T>) -> Self

Aliases a local binding, preserving a shared source when one exists.
Source§

impl<T: SharedPropertyValue + Serialize> Serialize for Property<T>

Source§

fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>

Serialize this value into the given Serde serializer. Read more
Source§

impl<T: ToPaxValue + SharedPropertyValue> ToPaxValue for Property<T>

Source§

fn nested_properties(&self) -> Vec<UntypedProperty>

Live properties read when snapshotting a compound value for PAXEL. Adapters observe these as well as the containing property.
Source§

fn to_pax_value(self) -> PaxValue

Converts this value into a PaxValue.
Source§

fn to_pax_value_in_graph(self) -> PaxValue
where Self: Sized,

Converts against owner-thread graph views, including nested generated property fields. Requires an entered property graph for shared fields. Ordinary Self::to_pax_value reads published value snapshots.

Auto Trait Implementations§

§

impl<T> Freeze for Property<T>
where Arc<SharedCell<T>>: Freeze,

§

impl<T> RefUnwindSafe for Property<T>
where Arc<SharedCell<T>>: RefUnwindSafe,

§

impl<T> Send for Property<T>
where Arc<SharedCell<T>>: Send,

§

impl<T> Sync for Property<T>
where Arc<SharedCell<T>>: Sync,

§

impl<T> Unpin for Property<T>
where Arc<SharedCell<T>>: Unpin,

§

impl<T> UnsafeUnpin for Property<T>
where Arc<SharedCell<T>>: UnsafeUnpin,

§

impl<T> UnwindSafe for Property<T>
where Arc<SharedCell<T>>: UnwindSafe,

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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> PropertyValue for T
where T: Default + Clone + Interpolatable + 'static,

Source§

impl<T> RoundFrom<T> for T

Source§

fn round_from(x: T) -> T

Performs the conversion.
Source§

impl<T, U> RoundInto<U> for T
where U: RoundFrom<T>,

Source§

fn round_into(self) -> U

Performs the conversion.
Source§

impl<T> SharedPropertyValue for T
where T: PropertyValue + Send + Sync,

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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more