Struct fyrox_core::variable::InheritableVariable
source · 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: Clone> InheritableVariable<T>
impl<T: Clone> InheritableVariable<T>
sourcepub fn clone_inner(&self) -> T
pub fn clone_inner(&self) -> T
Clones wrapped value.
sourcepub fn try_sync_model<S: FnOnce(T)>(&self, setter: S) -> bool
pub fn try_sync_model<S: FnOnce(T)>(&self, setter: S) -> bool
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) -> Self
pub fn new_modified(value: T) -> Self
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) -> Self
pub fn new_non_modified(value: T) -> Self
Creates new variable without any flags set.
sourcepub fn new_with_flags(value: T, flags: VariableFlags) -> Self
pub fn new_with_flags(value: T, flags: VariableFlags) -> Self
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> Clone for InheritableVariable<T>
impl<T: Clone> Clone for InheritableVariable<T>
source§impl<T: Debug> Debug for InheritableVariable<T>
impl<T: Debug> Debug for InheritableVariable<T>
source§impl<T: Default> Default for InheritableVariable<T>
impl<T: Default> Default for 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§impl<T: PartialEq> PartialEq for InheritableVariable<T>
impl<T: PartialEq> PartialEq for InheritableVariable<T>
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<Self>) -> Box<dyn Any>
fn as_any(&self, func: &mut dyn FnMut(&dyn Any))
fn as_any_mut(&mut self, func: &mut dyn FnMut(&mut dyn Any))
fn as_reflect(&self, func: &mut dyn FnMut(&dyn Reflect))
fn as_reflect_mut(&mut self, func: &mut dyn FnMut(&mut dyn Reflect))
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>))
fn fields_mut(&mut self, func: &mut dyn FnMut(Vec<&mut dyn Reflect>))
fn field(&self, name: &str, func: &mut dyn FnMut(Option<&dyn Reflect>))
fn field_mut( &mut self, name: &str, func: &mut dyn FnMut(Option<&mut dyn Reflect>) )
fn as_array(&self, func: &mut dyn FnMut(Option<&dyn ReflectArray>))
fn as_array_mut(&mut self, func: &mut dyn FnMut(Option<&mut dyn ReflectArray>))
fn as_list(&self, func: &mut dyn FnMut(Option<&dyn ReflectList>))
fn as_list_mut(&mut self, func: &mut dyn FnMut(Option<&mut dyn ReflectList>))
fn as_inheritable_variable( &self, func: &mut dyn FnMut(Option<&dyn ReflectInheritableVariable>) )
fn as_inheritable_variable_mut( &mut self, func: &mut dyn FnMut(Option<&mut dyn ReflectInheritableVariable>) )
fn as_hash_map(&self, func: &mut dyn FnMut(Option<&dyn ReflectHashMap>))
fn as_hash_map_mut( &mut self, func: &mut dyn FnMut(Option<&mut dyn ReflectHashMap>) )
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
) -> Result<Option<Box<dyn Reflect>>, InheritError>
fn try_inherit( &mut self, parent: &dyn ReflectInheritableVariable ) -> 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) -> bool
fn value_equals(&self, other: &dyn ReflectInheritableVariable) -> 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
fn inner_value_mut(&mut self) -> &mut dyn Reflect
source§fn inner_value_ref(&self) -> &dyn Reflect
fn inner_value_ref(&self) -> &dyn Reflect
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> Eq for InheritableVariable<T>
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
source§impl<T> FieldValue for Twhere
T: 'static,
impl<T> FieldValue for Twhere T: 'static,
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<'p, T: Reflect>( &self, path: &'p str, func: &mut dyn FnMut(Result<&T, ReflectPathError<'p>>) )
fn get_resolve_path_mut<'p, T: Reflect>( &mut self, path: &'p str, func: &mut dyn FnMut(Result<&mut T, ReflectPathError<'p>>) )
§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.