pub struct InheritableVariable<T> { /* private fields */ }Expand description
A wrapper for a variable that hold additional flag that tells that initial value was changed in runtime.
InheritableVariables are used for resource inheritance system. Resource inheritance may just sound weird, but the idea behind it is very simple - take property values from parent resource if the value in current hasn’t changed in runtime.
To get better understanding, let’s look at very simple example. Imagine you have a scene with a 3d model instance. Now you realizes that the 3d model has a misplaced object and you need to fix it, you open a 3D modelling software (Blender, 3Ds max, etc) and move the object to a correct spot and re-save the 3D model. The question is: what should happen with the instance of the object in the scene? Logical answer would be: if it hasn’t been modified, then just take the new position from the 3D model. This is where inheritable variable comes into play. If you’ve change the value of such variable, it will remember changes and the object will stay on its new position instead of changed.
Deref and DerefMut
Access via Deref provides access to inner variable. DerefMut marks variable as modified and returns a mutable reference to inner variable.
Implementations§
source§impl<T> InheritableVariable<T>where
T: Clone,
impl<T> InheritableVariable<T>where T: Clone,
sourcepub fn clone_inner(&self) -> T
pub fn clone_inner(&self) -> T
Clones wrapped value.
sourcepub fn try_sync_model<S>(&self, setter: S) -> boolwhere
S: FnOnce(T),
pub fn try_sync_model<S>(&self, setter: S) -> boolwhere S: FnOnce(T),
Tries to sync a value in a data model with a value in the inheritable variable. The value will be synced only if it was marked as needs sync.
source§impl<T> InheritableVariable<T>
impl<T> InheritableVariable<T>
sourcepub fn new_modified(value: T) -> InheritableVariable<T>
pub fn new_modified(value: T) -> InheritableVariable<T>
Creates new modified variable from given value. This method should always be used to create inheritable variables in the engine.
sourcepub fn new_non_modified(value: T) -> InheritableVariable<T>
pub fn new_non_modified(value: T) -> InheritableVariable<T>
Creates new variable without any flags set.
sourcepub fn new_with_flags(value: T, flags: VariableFlags) -> InheritableVariable<T>
pub fn new_with_flags(value: T, flags: VariableFlags) -> InheritableVariable<T>
Creates new variable from a given value with custom flags.
sourcepub fn set_value_and_mark_modified(&mut self, value: T) -> T
pub fn set_value_and_mark_modified(&mut self, value: T) -> T
Replaces value and also raises the VariableFlags::MODIFIED flag.
sourcepub fn set_value_with_flags(&mut self, value: T, flags: VariableFlags) -> T
pub fn set_value_with_flags(&mut self, value: T, flags: VariableFlags) -> T
Replaces value and flags.
sourcepub fn set_value_silent(&mut self, value: T) -> T
pub fn set_value_silent(&mut self, value: T) -> T
Replaces current value without marking the variable modified.
sourcepub fn need_sync(&self) -> bool
pub fn need_sync(&self) -> bool
Returns true if the respective data model’s variable must be synced.
sourcepub fn get_value_ref(&self) -> &T
pub fn get_value_ref(&self) -> &T
Returns a reference to the wrapped value.
sourcepub fn get_value_mut_and_mark_modified(&mut self) -> &mut T
pub fn get_value_mut_and_mark_modified(&mut self) -> &mut T
Returns a mutable reference to the wrapped value.
Important notes.
The method raises modified flag, no matter if actual modification was made!
sourcepub fn get_value_mut_silent(&mut self) -> &mut T
pub fn get_value_mut_silent(&mut self) -> &mut T
Returns a mutable reference to the wrapped value.
Important notes.
This method does not mark the value as modified!
sourcepub fn is_modified(&self) -> bool
pub fn is_modified(&self) -> bool
Returns true if variable was modified and should not be overwritten during property inheritance.
sourcepub fn mark_modified(&mut self)
pub fn mark_modified(&mut self)
Marks value as modified, so its value won’t be overwritten during property inheritance.
Trait Implementations§
source§impl<T> Clone for InheritableVariable<T>where
T: Clone,
impl<T> Clone for InheritableVariable<T>where T: Clone,
source§fn clone(&self) -> InheritableVariable<T>
fn clone(&self) -> InheritableVariable<T>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moresource§impl<T> Debug for InheritableVariable<T>where
T: Debug,
impl<T> Debug for InheritableVariable<T>where T: Debug,
source§impl<T> Default for InheritableVariable<T>where
T: Default,
impl<T> Default for InheritableVariable<T>where T: Default,
source§fn default() -> InheritableVariable<T>
fn default() -> InheritableVariable<T>
source§impl<T> DerefMut for InheritableVariable<T>
impl<T> DerefMut for InheritableVariable<T>
source§impl<T> From<T> for InheritableVariable<T>
impl<T> From<T> for InheritableVariable<T>
source§fn from(v: T) -> InheritableVariable<T>
fn from(v: T) -> InheritableVariable<T>
source§impl<T> PartialEq for InheritableVariable<T>where
T: PartialEq,
impl<T> PartialEq for InheritableVariable<T>where T: PartialEq,
source§fn eq(&self, other: &InheritableVariable<T>) -> bool
fn eq(&self, other: &InheritableVariable<T>) -> bool
self and other values to be equal, and is used
by ==.source§impl<T> Reflect for InheritableVariable<T>where
T: Reflect + Clone + PartialEq + Debug,
impl<T> Reflect for InheritableVariable<T>where T: Reflect + Clone + PartialEq + Debug,
fn type_name(&self) -> &'static str
fn doc(&self) -> &'static str
fn fields_info(&self, func: &mut dyn FnMut(Vec<FieldInfo<'_, '_>>))
fn into_any(self: Box<InheritableVariable<T>>) -> Box<dyn Any>
fn as_any(&self, func: &mut dyn FnMut(&(dyn Any + 'static)))
fn as_any_mut(&mut self, func: &mut dyn FnMut(&mut (dyn Any + 'static)))
fn as_reflect(&self, func: &mut dyn FnMut(&(dyn Reflect + 'static)))
fn as_reflect_mut(&mut self, func: &mut dyn FnMut(&mut (dyn Reflect + 'static)))
fn set( &mut self, value: Box<dyn Reflect> ) -> Result<Box<dyn Reflect>, Box<dyn Reflect>>
source§fn set_field(
&mut self,
field: &str,
value: Box<dyn Reflect>,
func: &mut dyn FnMut(Result<Box<dyn Reflect>, Box<dyn Reflect>>)
)
fn set_field( &mut self, field: &str, value: Box<dyn Reflect>, func: &mut dyn FnMut(Result<Box<dyn Reflect>, Box<dyn Reflect>>) )
#[reflect(setter = ..)] or falls back to
Reflect::field_mutfn fields(&self, func: &mut dyn FnMut(Vec<&(dyn Reflect + 'static)>))
fn fields_mut( &mut self, func: &mut dyn FnMut(Vec<&mut (dyn Reflect + 'static)>) )
fn field( &self, name: &str, func: &mut dyn FnMut(Option<&(dyn Reflect + 'static)>) )
fn field_mut( &mut self, name: &str, func: &mut dyn FnMut(Option<&mut (dyn Reflect + 'static)>) )
fn as_array(&self, func: &mut dyn FnMut(Option<&(dyn ReflectArray + 'static)>))
fn as_array_mut( &mut self, func: &mut dyn FnMut(Option<&mut (dyn ReflectArray + 'static)>) )
fn as_list(&self, func: &mut dyn FnMut(Option<&(dyn ReflectList + 'static)>))
fn as_list_mut( &mut self, func: &mut dyn FnMut(Option<&mut (dyn ReflectList + 'static)>) )
fn as_inheritable_variable( &self, func: &mut dyn FnMut(Option<&(dyn ReflectInheritableVariable + 'static)>) )
fn as_inheritable_variable_mut( &mut self, func: &mut dyn FnMut(Option<&mut (dyn ReflectInheritableVariable + 'static)>) )
fn as_hash_map( &self, func: &mut dyn FnMut(Option<&(dyn ReflectHashMap + 'static)>) )
fn as_hash_map_mut( &mut self, func: &mut dyn FnMut(Option<&mut (dyn ReflectHashMap + 'static)>) )
source§impl<T> ReflectInheritableVariable for InheritableVariable<T>where
T: Reflect + Clone + PartialEq + Debug,
impl<T> ReflectInheritableVariable for InheritableVariable<T>where T: Reflect + Clone + PartialEq + Debug,
source§fn try_inherit(
&mut self,
parent: &(dyn ReflectInheritableVariable + 'static)
) -> Result<Option<Box<dyn Reflect>>, InheritError>
fn try_inherit( &mut self, parent: &(dyn ReflectInheritableVariable + 'static) ) -> Result<Option<Box<dyn Reflect>>, InheritError>
source§fn reset_modified_flag(&mut self)
fn reset_modified_flag(&mut self)
source§fn flags(&self) -> VariableFlags
fn flags(&self) -> VariableFlags
fn set_flags(&mut self, flags: VariableFlags)
source§fn is_modified(&self) -> bool
fn is_modified(&self) -> bool
source§fn value_equals(
&self,
other: &(dyn ReflectInheritableVariable + 'static)
) -> bool
fn value_equals( &self, other: &(dyn ReflectInheritableVariable + 'static) ) -> bool
source§fn clone_value_box(&self) -> Box<dyn Reflect>
fn clone_value_box(&self) -> Box<dyn Reflect>
source§fn mark_modified(&mut self)
fn mark_modified(&mut self)
source§fn inner_value_mut(&mut self) -> &mut (dyn Reflect + 'static)
fn inner_value_mut(&mut self) -> &mut (dyn Reflect + 'static)
source§fn inner_value_ref(&self) -> &(dyn Reflect + 'static)
fn inner_value_ref(&self) -> &(dyn Reflect + 'static)
source§impl<T> Visit for InheritableVariable<T>where
T: Visit,
impl<T> Visit for InheritableVariable<T>where T: Visit,
source§impl<T> Deref for InheritableVariable<T>
impl<T> Deref for InheritableVariable<T>
impl<T> Eq for InheritableVariable<T>where T: Eq,
Auto Trait Implementations§
impl<T> !RefUnwindSafe for InheritableVariable<T>
impl<T> Send for InheritableVariable<T>where T: Send,
impl<T> !Sync for InheritableVariable<T>
impl<T> Unpin for InheritableVariable<T>where T: Unpin,
impl<T> UnwindSafe for InheritableVariable<T>where T: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
source§impl<T> FieldValue for Twhere
T: 'static,
impl<T> FieldValue for Twhere T: 'static,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§impl<T> Pointable for T
impl<T> Pointable for T
source§impl<T> ResolvePath for Twhere
T: Reflect,
impl<T> ResolvePath for Twhere T: Reflect,
fn resolve_path<'p>( &self, path: &'p str, func: &mut dyn FnMut(Result<&(dyn Reflect + 'static), ReflectPathError<'p>>) )
fn resolve_path_mut<'p>( &mut self, path: &'p str, func: &mut dyn FnMut(Result<&mut (dyn Reflect + 'static), ReflectPathError<'p>>) )
fn get_resolve_path<T, 'p>( &self, path: &'p str, func: &mut dyn FnMut(Result<&T, ReflectPathError<'p>>) )where T: Reflect,
fn get_resolve_path_mut<T, 'p>( &mut self, path: &'p str, func: &mut dyn FnMut(Result<&mut T, ReflectPathError<'p>>) )where T: Reflect,
source§impl<T> ScriptMessagePayload for Twhere
T: 'static + Send,
impl<T> ScriptMessagePayload for Twhere T: 'static + Send,
source§fn as_any_ref(&self) -> &(dyn Any + 'static)
fn as_any_ref(&self) -> &(dyn Any + 'static)
self as &dyn Anysource§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
self as &dyn Any§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.