Struct bevy_retrograde::ui::raui::core::data_binding::DataBinding [−]
Expand description
Wraps internal data and optionally notifies an Application
of changes to it
See module docs for a full example.
Implementations
impl<T> DataBinding<T> where
T: Debug + Default + Send + Sync,
impl<T> DataBinding<T> where
T: Debug + Default + Send + Sync,
pub fn new(data: T) -> DataBinding<T>
pub fn new(data: T) -> DataBinding<T>
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.
pub fn new_bound(data: T, notifier: ChangeNotifier) -> DataBinding<T>
pub fn new_bound(data: T, notifier: ChangeNotifier) -> DataBinding<T>
Create a new DataBinding
that wraps data
and notifies an
Application
’s ChangeNotifier
when the data is
mutated.
pub fn bind(&mut self, notifier: ChangeNotifier)
pub fn bind(&mut self, notifier: ChangeNotifier)
Bind this DataBinding
to a ChangeNotifier
pub fn unbind(&mut self)
pub fn unbind(&mut self)
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));
pub fn read_cloned(&self) -> Option<T> where
T: Clone,
pub fn read_cloned(&self) -> Option<T> where
T: Clone,
pub fn read_cloned_or_default(&self) -> T where
T: Clone,
pub fn read_cloned_or_default(&self) -> T where
T: Clone,
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));
pub fn write(&mut self, v: T)
pub fn write(&mut self, v: T)
Set the inner data directly and notify the ChangeNotifier
( if set )
Trait Implementations
pub fn clone(&self) -> DataBinding<T>
pub fn clone(&self) -> DataBinding<T>
Returns a copy of the value. Read more
Performs copy-assignment from source
. Read more
pub fn default() -> DataBinding<T>
pub fn default() -> DataBinding<T>
Returns the “default value” for a type. Read more
impl<'de, T> Deserialize<'de> for DataBinding<T> where
T: Debug + Default + Send + Sync,
impl<'de, T> Deserialize<'de> for DataBinding<T> where
T: Debug + Default + Send + Sync,
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,
pub fn clone_message(&self) -> Box<dyn MessageData + 'static, Global>
fn from_prefab(data: Value) -> Result<Self, PrefabError>
fn to_prefab(&self) -> Result<Value, PrefabError>
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
impl<T> Downcast for T where
T: Any,
impl<T> Downcast for T where
T: Any,
Convert Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
. Read more
pub fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
pub fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
Convert Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
. Read more
Convert &Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s. Read more
pub fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
pub fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert &mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s. Read more
impl<T> FromWorld for T where
T: Default,
impl<T> FromWorld for T where
T: Default,
pub fn from_world(_world: &mut World) -> T
pub fn from_world(_world: &mut World) -> T
Creates Self
using data from the given [World]
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
pub fn clone_type_data(&self) -> Box<dyn TypeData + 'static, Global>
pub fn vzip(self) -> V