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§

source

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.

source

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 $.

source

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.

source

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.

source

fn variables(&self) -> HashMap<String, YarnValue>

Returns a map of all variables in this variable storage.

source

fn clear(&mut self)

Clears all variables in this variable storage.

source

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.

source

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§

source

fn contains(&self, name: &str) -> bool

Returns true if the variable is defined, false otherwise.

Trait Implementations§

source§

impl Clone for Box<dyn VariableStorage>

source§

fn clone(&self) -> Box<dyn VariableStorage>

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 Extend<(String, YarnValue)> for Box<dyn VariableStorage>

source§

fn extend<T>(&mut self, iter: T)
where T: IntoIterator<Item = (String, YarnValue)>,

Extends a collection with the contents of an iterator. Read more
source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more

Implementors§