Struct knightrs::Variable[][src]

pub struct Variable(_);

A variable within Knight.

Note that there is no way to create Variables 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]

#[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 assigned 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 Values 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

impl Borrow<str> for Variable[src]

impl Clone for Variable[src]

impl Debug for Variable[src]

impl Eq for Variable[src]

impl From<Variable> for Value[src]

impl Hash for Variable[src]

impl PartialEq<Variable> for Variable[src]

fn eq(&self, rhs: &Self) -> bool[src]

Checks to see if two variables are the same.

This will only return true if they both originate from the same Environment and have the same name.

Auto Trait Implementations

impl !RefUnwindSafe for Variable

impl !Send for Variable

impl !Sync for Variable

impl Unpin for Variable

impl !UnwindSafe for Variable

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,