Struct oxygengine_user_interface::raui::core::data_binding::DataBinding [−][src]
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));
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 the “default value” for a type. Read more
pub fn deserialize<__D>(
__deserializer: __D
) -> Result<DataBinding<T>, <__D as Deserializer<'de>>::Error> where
__D: Deserializer<'de>,
pub fn deserialize<__D>(
__deserializer: __D
) -> Result<DataBinding<T>, <__D as Deserializer<'de>>::Error> where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl<T> MessageData for DataBinding<T> where
T: 'static + Debug + Default + Send + Sync,
DataBinding<T>: Clone,
impl<T> MessageData for DataBinding<T> where
T: 'static + Debug + Default + Send + Sync,
DataBinding<T>: Clone,
impl<T> PropsData for DataBinding<T> where
T: 'static + Debug + Default + Send + Sync,
DataBinding<T>: Clone,
impl<T> PropsData for DataBinding<T> where
T: 'static + Debug + Default + Send + Sync,
DataBinding<T>: Clone,
pub fn serialize<__S>(
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error> where
__S: Serializer,
pub fn serialize<__S>(
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error> where
__S: Serializer,
Serialize this value into the given Serde serializer. Read more
Auto Trait Implementations
impl<T> RefUnwindSafe for DataBinding<T>
impl<T> Send for DataBinding<T>
impl<T> Sync for DataBinding<T>
impl<T> Unpin for DataBinding<T>
impl<T> UnwindSafe for DataBinding<T>
Blanket Implementations
Mutably borrows from an owned value. Read more