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§impl<T> Reflect for InheritableVariable<T>
impl<T> Reflect for InheritableVariable<T>
fn source_path() -> &'static str
fn type_name(&self) -> &'static str
fn doc(&self) -> &'static str
Source§fn assembly_name(&self) -> &'static str
fn assembly_name(&self) -> &'static str
#[derive(Reflect)]
) to ensure that this method will return correct assembly
name. In other words - there’s no guarantee, that any implementation other than proc-macro
will return a correct name of the assembly. Alternatively, you can use env!("CARGO_PKG_NAME")
as an implementation.Source§fn type_assembly_name() -> &'static str
fn type_assembly_name() -> &'static str
#[derive(Reflect)]
) to ensure that this method will return correct assembly
name. In other words - there’s no guarantee, that any implementation other than proc-macro
will return a correct name of the assembly. Alternatively, you can use env!("CARGO_PKG_NAME")
as an implementation.fn fields_info(&self, func: &mut dyn FnMut(&[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_mut
fn fields(&self, func: &mut dyn FnMut(&[&(dyn Reflect + 'static)]))
fn fields_mut( &mut self, func: &mut dyn FnMut(&mut [&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>
impl<T> ReflectInheritableVariable for InheritableVariable<T>
Source§fn try_inherit(
&mut self,
parent: &(dyn ReflectInheritableVariable + 'static),
ignored_types: &[TypeId],
) -> Result<Option<Box<dyn Reflect>>, InheritError>
fn try_inherit( &mut self, parent: &(dyn ReflectInheritableVariable + 'static), ignored_types: &[TypeId], ) -> 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,
Special non-derived implementation of Visit to account for the special needs of InheritableVariable from Visitors.
impl<T> Visit for InheritableVariable<T>where
T: Visit,
Special non-derived implementation of Visit to account for the special needs of InheritableVariable from Visitors.
Source§fn visit(&mut self, name: &str, visitor: &mut Visitor) -> Result<(), VisitError>
fn visit(&mut self, name: &str, visitor: &mut Visitor) -> Result<(), VisitError>
Read or write this value, depending on whether Visitor::is_reading() is true or false. InheritableVariable uses the visit method in a very special way. Rather than just directly visiting the inner value and flags of the InheritableVariable, it allows for several distinct possibilities.
§Cases when the visitor is reading:
-
If the visitor is reading, InheritableVariable allows for the possibilities that the data being read is not an InheritableVariable but is data of type T. It uses this data to set the inner value and adds VariableFlags::MODIFIED to InheritableVariable::flags.
-
The data for this InheritableVariable may be missing entirely from the given visitor. If so, then leave inner value unmodified and remove the
MODIFIED
flag fromflags
.
§Cases when the visitor is writing:
-
If the visitor is writing and the
MODIFIED
flag is not set, then InheritableVariable writes nothing at all. It does not even write an empty region. -
If the visitor is writing and the
MODIFIED
flag is set, then the InheritableVariable writes itself to the Visitor as if InheritableVariable were a normal struct, writing a Field for “Flags” and causingvalue
to write itself.
If the VisitorFlags::SERIALIZE_EVERYTHING flag is set in the Visitor::flags, this causes the InheritableVariable to act
as if its MODIFIED
flag were set.
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> !Freeze for InheritableVariable<T>
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> AsyncTaskResult for T
impl<T> AsyncTaskResult for T
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§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
.Source§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
.Source§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.Source§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.Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Any
. Could be used to downcast a trait object
to a particular type.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Any
. Could be used to downcast a trait object
to a particular type.fn into_any(self: Box<T>) -> Box<dyn Any>
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.Source§impl<T> FieldValue for Twhere
T: 'static,
impl<T> FieldValue for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> MessageData for T
impl<T> MessageData for T
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian()
.Source§impl<T> ReflectBase for Twhere
T: Reflect,
impl<T> ReflectBase for Twhere
T: Reflect,
fn as_any_raw(&self) -> &(dyn Any + 'static)
fn as_any_raw_mut(&mut self) -> &mut (dyn Any + '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>(
&self,
path: &'p str,
func: &mut dyn FnMut(Result<&T, ReflectPathError<'p>>),
)where
T: Reflect,
fn get_resolve_path_mut<'p, T>(
&mut self,
path: &'p str,
func: &mut dyn FnMut(Result<&mut T, ReflectPathError<'p>>),
)where
T: Reflect,
Source§impl<T> ScriptMessagePayload for T
impl<T> ScriptMessagePayload for T
Source§fn as_any_ref(&self) -> &(dyn Any + 'static)
fn as_any_ref(&self) -> &(dyn Any + 'static)
self
as &dyn Any
Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
self
as &dyn Any
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self
from the equivalent element of its
superset. Read moreSource§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).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset
but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self
to the equivalent element of its superset.