Trait bevy_yarnspinner::prelude::VariableStorage
pub trait VariableStorage: Debug + Send + Sync {
// Required methods
fn clone_shallow(&self) -> Box<dyn VariableStorage>;
fn set(
&mut self,
name: String,
value: YarnValue
) -> Result<(), VariableStorageError>;
fn get(&self, name: &str) -> Result<YarnValue, VariableStorageError>;
fn extend(
&mut self,
values: HashMap<String, YarnValue>
) -> Result<(), VariableStorageError>;
fn variables(&self) -> HashMap<String, YarnValue>;
fn clear(&mut self);
fn as_any(&self) -> &(dyn Any + 'static);
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static);
// Provided method
fn contains(&self, name: &str) -> bool { ... }
}
Expand description
Provides a mechanism for storing and retrieving instances
of the YarnValue
type.
§Implementation notes
The interface has been changed to make use of our YarnValue
type,
which is more domain specific than the semi-corresponding Convertible
.
We also cannot use generics in this trait because we need to be able to clone this box.
Required Methods§
fn clone_shallow(&self) -> Box<dyn VariableStorage>
fn clone_shallow(&self) -> Box<dyn VariableStorage>
Creates a shallow clone of this variable storage, i.e. a clone that shares the same underlying storage and will thus be perfectly in sync with the original instance.
fn set(
&mut self,
name: String,
value: YarnValue
) -> Result<(), VariableStorageError>
fn set( &mut self, name: String, value: YarnValue ) -> Result<(), VariableStorageError>
Sets the value of a variable. Must fail with a [VariableStorageError::InvalidVariableName
] if the variable name does not start with a $
.
fn get(&self, name: &str) -> Result<YarnValue, VariableStorageError>
fn get(&self, name: &str) -> Result<YarnValue, VariableStorageError>
Gets the value of a variable. Must fail with a [VariableStorageError::InvalidVariableName
] if the variable name does not start with a $
.
If the variable is not defined, must fail with a [VariableStorageError::VariableNotFound
].
fn extend(
&mut self,
values: HashMap<String, YarnValue>
) -> Result<(), VariableStorageError>
fn extend( &mut self, values: HashMap<String, YarnValue> ) -> Result<(), VariableStorageError>
Extends this variable storage with the given values. Must fail with a [VariableStorageError::InvalidVariableName
] if any of the variable names do not start with a $
.
Existing variables must be overwritten.
fn variables(&self) -> HashMap<String, YarnValue>
fn variables(&self) -> HashMap<String, YarnValue>
Returns a map of all variables in this variable storage.
fn clear(&mut self)
fn clear(&mut self)
Clears all variables in this variable storage.
fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Gets the VariableStorage
as a trait object.
This allows retrieving the concrete type by downcasting, using the downcast_ref
method available through the Any
trait.
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Gets the VariableStorage
as a mutable trait object.
This allows retrieving the concrete type by downcasting, using the downcast_mut
method available through the Any
trait.
Provided Methods§
Trait Implementations§
§impl Clone for Box<dyn VariableStorage>
impl Clone for Box<dyn VariableStorage>
§fn clone(&self) -> Box<dyn VariableStorage>
fn clone(&self) -> Box<dyn VariableStorage>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more§impl Extend<(String, YarnValue)> for Box<dyn VariableStorage>
impl Extend<(String, YarnValue)> for Box<dyn VariableStorage>
source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)