Skip to main content

VariableStorage

Trait VariableStorage 

Source
pub trait VariableStorage {
    // Required methods
    fn get(&self, name: &str) -> Option<Value>;
    fn set(&mut self, name: &str, value: Value);
}
Expand description

Pluggable variable storage consumed by the runner.

Implement this trait to back variables with your game’s own data model (e.g. an ECS component, a database row, or a save-file entry).

§Example

use bubbles::{HashMapStorage, Value, VariableStorage};

let mut s = HashMapStorage::new();
s.set("$score", Value::Number(10.0));
assert_eq!(s.get("$score"), Some(Value::Number(10.0)));
assert_eq!(s.get("$missing"), None);

Required Methods§

Source

fn get(&self, name: &str) -> Option<Value>

Returns the current value of name, or None if the variable has not been set.

Source

fn set(&mut self, name: &str, value: Value)

Stores value under name, replacing any previous value.

Implementors§