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>
impl<T: SharedPropertyValue> Property<T>
Sourcepub fn new(value: T) -> Self
pub fn new(value: T) -> Self
Creates independent shared state. No UI thread or graph is required.
Sourcepub fn published(&self) -> Published<T>
pub fn published(&self) -> Published<T>
Export read-only shared snapshots, including owner-thread computed output.
Sourcepub fn read<R>(&self, f: impl FnOnce(&T) -> R) -> R
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.
Sourcepub fn observed_revision(&self) -> Option<u64>
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.
Sourcepub fn set(&self, value: T)
pub fn set(&self, value: T)
Atomically publishes a value and requests work from attached graphs.
Sourcepub fn update(&self, f: impl FnOnce(&mut T))
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.
Sourcepub fn set_if_neq(&self, value: T) -> boolwhere
T: PartialEq,
pub fn set_if_neq(&self, value: T) -> boolwhere
T: PartialEq,
Compares and publishes under the same single-property write operation.
Sourcepub fn local(&self) -> LocalProperty<T>
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.
Sourcepub fn untyped(&self) -> UntypedProperty
pub fn untyped(&self) -> UntypedProperty
Returns a local dependency handle. This handle cannot cross threads.
Sourcepub fn replace_with(&self, source: LocalProperty<T>)
pub fn replace_with(&self, source: LocalProperty<T>)
Installs an owner-thread binding while retaining this shared identity.
Trait Implementations§
Source§impl<T: SharedPropertyValue> Default for Property<T>
impl<T: SharedPropertyValue> Default for Property<T>
Source§impl<'de, T: SharedPropertyValue + Deserialize<'de>> Deserialize<'de> for Property<T>
impl<'de, T: SharedPropertyValue + Deserialize<'de>> Deserialize<'de> for Property<T>
Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
Source§impl<T: SharedPropertyValue> Interpolatable for Property<T>
impl<T: SharedPropertyValue> Interpolatable for Property<T>
Source§fn interpolate(&self, other: &Self, t: f64) -> Self
fn interpolate(&self, other: &Self, t: f64) -> Self
Source§impl<T: SharedPropertyValue> PropertyBinding<T> for Property<T>
impl<T: SharedPropertyValue> PropertyBinding<T> for Property<T>
Source§fn from_value(value: T) -> Self
fn from_value(value: T) -> Self
Source§fn local(&self) -> LocalProperty<T>
fn local(&self) -> LocalProperty<T>
Source§fn from_local(source: LocalProperty<T>) -> Self
fn from_local(source: LocalProperty<T>) -> Self
Source§impl<T: ToPaxValue + SharedPropertyValue> ToPaxValue for Property<T>
impl<T: ToPaxValue + SharedPropertyValue> ToPaxValue for Property<T>
Source§fn nested_properties(&self) -> Vec<UntypedProperty>
fn nested_properties(&self) -> Vec<UntypedProperty>
Source§fn to_pax_value(self) -> PaxValue
fn to_pax_value(self) -> PaxValue
PaxValue.Source§fn to_pax_value_in_graph(self) -> PaxValuewhere
Self: Sized,
fn to_pax_value_in_graph(self) -> PaxValuewhere
Self: Sized,
Self::to_pax_value reads published value snapshots.