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> Property<T>where
T: SharedPropertyValue,
impl<T> Property<T>where
T: SharedPropertyValue,
Sourcepub fn new(value: T) -> Property<T>
pub fn new(value: T) -> Property<T>
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> Default for Property<T>where
T: SharedPropertyValue,
impl<T> Default for Property<T>where
T: SharedPropertyValue,
Source§impl<'de, T> Deserialize<'de> for Property<T>where
T: SharedPropertyValue + Deserialize<'de>,
impl<'de, T> Deserialize<'de> for Property<T>where
T: SharedPropertyValue + Deserialize<'de>,
Source§fn deserialize<D>(
deserializer: D,
) -> Result<Property<T>, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D,
) -> Result<Property<T>, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
Source§impl<T> Interpolatable for Property<T>where
T: SharedPropertyValue,
impl<T> Interpolatable for Property<T>where
T: SharedPropertyValue,
Source§impl<T> PropertyBinding<T> for Property<T>where
T: SharedPropertyValue,
impl<T> PropertyBinding<T> for Property<T>where
T: SharedPropertyValue,
Source§fn from_value(value: T) -> Property<T>
fn from_value(value: T) -> Property<T>
Source§fn local(&self) -> LocalProperty<T>
fn local(&self) -> LocalProperty<T>
Source§fn from_local(source: LocalProperty<T>) -> Property<T>
fn from_local(source: LocalProperty<T>) -> Property<T>
Source§impl<T> Serialize for Property<T>where
T: SharedPropertyValue + Serialize,
impl<T> Serialize for Property<T>where
T: SharedPropertyValue + Serialize,
Source§fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
Source§impl<T> ToPaxValue for Property<T>where
T: ToPaxValue + SharedPropertyValue,
impl<T> ToPaxValue for Property<T>where
T: ToPaxValue + SharedPropertyValue,
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.