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>

source

pub fn clone_inner(&self) -> T

Clones wrapped value.

source

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>

source

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.

source

pub fn new_non_modified(value: T) -> Self

Creates new variable without any flags set.

source

pub fn new_with_flags(value: T, flags: VariableFlags) -> Self

Creates new variable from a given value with custom flags.

source

pub fn set_value_and_mark_modified(&mut self, value: T) -> T

Replaces value and also raises the VariableFlags::MODIFIED flag.

source

pub fn set_value_with_flags(&mut self, value: T, flags: VariableFlags) -> T

Replaces value and flags.

source

pub fn set_value_silent(&mut self, value: T) -> T

Replaces current value without marking the variable modified.

source

pub fn need_sync(&self) -> bool

Returns true if the respective data model’s variable must be synced.

source

pub fn get_value_ref(&self) -> &T

Returns a reference to the wrapped value.

source

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!

source

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!

source

pub fn is_modified(&self) -> bool

Returns true if variable was modified and should not be overwritten during property inheritance.

source

pub fn mark_modified(&mut self)

Marks value as modified, so its value won’t be overwritten during property inheritance.

source

pub fn take(self) -> T

Deconstructs the variable and returns the wrapped value.

Trait Implementations§

source§

impl<T: Clone> Clone for InheritableVariable<T>

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T: Debug> Debug for InheritableVariable<T>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<T: Default> Default for InheritableVariable<T>

source§

fn default() -> Self

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

impl<T> DerefMut for InheritableVariable<T>

source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
source§

impl<T> From<T> for InheritableVariable<T>

source§

fn from(v: T) -> Self

Converts to this type from the input type.
source§

impl<T: PartialEq> PartialEq for InheritableVariable<T>

source§

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T> Reflect for InheritableVariable<T>where T: Reflect + Clone + PartialEq + Debug,

source§

fn type_name(&self) -> &'static str

source§

fn doc(&self) -> &'static str

source§

fn fields_info(&self, func: &mut dyn FnMut(Vec<FieldInfo<'_, '_>>))

source§

fn into_any(self: Box<Self>) -> Box<dyn Any>

source§

fn as_any(&self, func: &mut dyn FnMut(&dyn Any))

source§

fn as_any_mut(&mut self, func: &mut dyn FnMut(&mut dyn Any))

source§

fn as_reflect(&self, func: &mut dyn FnMut(&dyn Reflect))

source§

fn as_reflect_mut(&mut self, func: &mut dyn FnMut(&mut dyn Reflect))

source§

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>>) )

Calls user method specified with #[reflect(setter = ..)] or falls back to Reflect::field_mut
source§

fn fields(&self, func: &mut dyn FnMut(Vec<&dyn Reflect>))

source§

fn fields_mut(&mut self, func: &mut dyn FnMut(Vec<&mut dyn Reflect>))

source§

fn field(&self, name: &str, func: &mut dyn FnMut(Option<&dyn Reflect>))

source§

fn field_mut( &mut self, name: &str, func: &mut dyn FnMut(Option<&mut dyn Reflect>) )

source§

fn as_array(&self, func: &mut dyn FnMut(Option<&dyn ReflectArray>))

source§

fn as_array_mut(&mut self, func: &mut dyn FnMut(Option<&mut dyn ReflectArray>))

source§

fn as_list(&self, func: &mut dyn FnMut(Option<&dyn ReflectList>))

source§

fn as_list_mut(&mut self, func: &mut dyn FnMut(Option<&mut dyn ReflectList>))

source§

fn as_inheritable_variable( &self, func: &mut dyn FnMut(Option<&dyn ReflectInheritableVariable>) )

source§

fn as_inheritable_variable_mut( &mut self, func: &mut dyn FnMut(Option<&mut dyn ReflectInheritableVariable>) )

source§

fn as_hash_map(&self, func: &mut dyn FnMut(Option<&dyn ReflectHashMap>))

source§

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,

source§

fn try_inherit( &mut self, parent: &dyn ReflectInheritableVariable ) -> Result<Option<Box<dyn Reflect>>, InheritError>

Tries to inherit a value from parent. It will succeed only if the current variable is not marked as modified.
source§

fn reset_modified_flag(&mut self)

Resets modified flag from the variable.
source§

fn flags(&self) -> VariableFlags

Returns current variable flags.
source§

fn set_flags(&mut self, flags: VariableFlags)

source§

fn is_modified(&self) -> bool

Returns true if value was modified.
source§

fn value_equals(&self, other: &dyn ReflectInheritableVariable) -> bool

Returns true if value equals to other’s value.
source§

fn clone_value_box(&self) -> Box<dyn Reflect>

Clones self value.
source§

fn mark_modified(&mut self)

Marks value as modified, so its value won’t be overwritten during property inheritance.
source§

fn inner_value_mut(&mut self) -> &mut dyn Reflect

Returns a mutable reference to wrapped value without marking the variable itself as modified.
source§

fn inner_value_ref(&self) -> &dyn Reflect

Returns a shared reference to wrapped value without marking the variable itself as modified.
source§

impl<T> Visit for InheritableVariable<T>where T: Visit,

source§

fn visit(&mut self, name: &str, visitor: &mut Visitor) -> VisitResult

source§

impl<T> Deref for InheritableVariable<T>

§

type Target = T

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

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> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> FieldValue for Twhere T: 'static,

source§

fn as_any(&self) -> &(dyn Any + 'static)

Casts self to a &dyn Any
source§

impl<T> From<!> for T

source§

fn from(t: !) -> T

Converts to this type from the input type.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<R> GetField for Rwhere R: Reflect,

source§

fn get_field<T>(&self, name: &str, func: &mut dyn FnMut(Option<&T>))where T: 'static,

source§

fn get_field_mut<T>(&mut self, name: &str, func: &mut dyn FnMut(Option<&mut T>))where T: 'static,

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ResolvePath for Twhere T: Reflect,

source§

fn resolve_path<'p>( &self, path: &'p str, func: &mut dyn FnMut(Result<&(dyn Reflect + 'static), ReflectPathError<'p>>) )

source§

fn resolve_path_mut<'p>( &mut self, path: &'p str, func: &mut dyn FnMut(Result<&mut (dyn Reflect + 'static), ReflectPathError<'p>>) )

source§

fn get_resolve_path<'p, T: Reflect>( &self, path: &'p str, func: &mut dyn FnMut(Result<&T, ReflectPathError<'p>>) )

source§

fn get_resolve_path_mut<'p, T: Reflect>( &mut self, path: &'p str, func: &mut dyn FnMut(Result<&mut T, ReflectPathError<'p>>) )

source§

impl<T> Same for T

§

type Output = T

Should always be Self
§

impl<SS, SP> SupersetOf<SS> for SPwhere SS: SubsetOf<SP>,

§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> Scalar for Twhere T: 'static + Clone + PartialEq + Debug,