Struct knightrs::Variable [−][src]
pub struct Variable(_);
A variable within Knight.
Note that there is no way to create Variable
s directly—they must to be fetched via Environment::get
.
All variables with the same from the same Environment
are identical. Updating any one of
them (via Variable::assign
) will update them all.
Implementations
impl Variable
[src]
impl Variable
[src]#[must_use]pub fn name(&self) -> &str
[src]
Fetches the name of the variable.
Examples
let mut env = Environment::default(); let var = env.get("plato"); assert_eq!(var.name(), "plato");
#[must_use = "this simply checks to see if it's assigned, and doesn't do anthing on its own."]pub fn is_assigned(&self) -> bool
[src]
Checks to see if the variable has been assign
ed to yet.
Examples
let mut env = Environment::default(); let var = env.get("plato"); assert!(!var.is_assigned()); var.assign(Value::Null); assert!(var.is_assigned());
pub fn assign(&self, value: Value)
[src]
Associates value
with this variable, so that fetch
will return it.
Any previously associated Value
s are discarded.
Note that all variables with the same name from the same environment will be affected. After all, that’s the point of having variables.
Examples
let mut env = Environment::default(); let var = env.get("plato"); let var2 = env.get("plato"); var.assign(Value::Null); assert_eq!(var.fetch().unwrap(), Value::Null); assert_eq!(var2.fetch().unwrap(), Value::Null);
#[must_use = "simply fetching a value does nothing; the return value should be inspected."]pub fn fetch(&self) -> Option<Value>
[src]
Returns the last value associated with this variable, or None
if nothing’s been associated.
Note that all variables with the same name from the same environment will be affected. After all, that’s the point of having variables.
Examples
let mut env = Environment::default(); let var = env.get("plato"); assert_eq!(var.fetch(), None); var.assign(Value::from(true)); assert_eq!(var.fetch(), Some(Value::from(true)));
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for Variable
impl !RefUnwindSafe for Variable
impl !UnwindSafe for Variable
impl !UnwindSafe for Variable