Struct raui_core::data_binding::DataBinding[][src]

pub struct DataBinding<T> where
    T: Debug + Default + Send + Sync
{ /* fields omitted */ }
Expand description

Wraps internal data and optionally notifies an Application of changes to it

See module docs for a full example.

Implementations

Create a new DataBinding that wraps data

It will create the data as unbound meaning that changes to the data will not notify any Application. The DataBinding can afterwards be bound with the bind method.

Create a new DataBinding that wraps data and notifies an Application’s ChangeNotifier when the data is mutated.

Bind this DataBinding to a ChangeNotifier

Unbind this DataBinding so that changes to the data no longer trigger application updates

Access the inner data of the binding inside of the provided closure

This will return None and will not run the supplied closure if a lock to the inner data cannot be obtained due to lock poisoning.

Example

let binding = DataBinding::new(false);

let x = binding.access(|data| {
    // Return the opposite of what's in our data
    !data
});

assert_eq!(x, Some(true));

Get a clone of the inner data

Returns None if the internal lock to the inner data has been poisoned.

Attempt to obtain a clone of the inner data or otherwise return the type’s default value

Use a closure to mutate the inner data and notify the ChangeNotifier ( if set )

This will return None and will not run the supplied closure if a lock to the inner data cannot be obtained due to lock poisoning.

Example

let mut binding = DataBinding::new(false);

let x = binding.mutate(|data| {
    // Update the data
    *data = true;

    *data
});

assert_eq!(x, Some(true));
assert_eq!(binding.read_cloned(), Some(true));

Set the inner data directly and notify the ChangeNotifier ( if set )

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

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

Deserialize this value from the given Serde deserializer. Read more

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.