Struct knightrs::Variable[][src]

pub struct Variable(_);
Expand description

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)));

pub fn run(&self) -> Result<Value>[src]

Executes this variable, returning an Error if the variable doesn’t exist.

Trait Implementations

impl Borrow<str> for Variable[src]

fn borrow(&self) -> &str[src]

Immutably borrows from an owned value. Read more

impl Clone for Variable[src]

fn clone(&self) -> Variable[src]

Returns a copy of the value. Read more

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl Debug for Variable[src]

fn fmt(&self, f: &mut Formatter<'_>) -> Result[src]

Formats the value using the given formatter. Read more

impl From<Variable> for Value[src]

fn from(variable: Variable) -> Self[src]

Performs the conversion.

impl Hash for Variable[src]

fn hash<H: Hasher>(&self, h: &mut H)[src]

Feeds this value into the given Hasher. Read more

fn hash_slice<H>(data: &[Self], state: &mut H) where
    H: Hasher
1.3.0[src]

Feeds a slice of this type into the given Hasher. Read more

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.

#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests for !=.

impl Eq for Variable[src]

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]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

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

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

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

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

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

pub fn from(t: T) -> T[src]

Performs the conversion.

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

pub fn into(self) -> U[src]

Performs the conversion.

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

type Owned = T

The resulting type after obtaining ownership.

pub fn to_owned(&self) -> T[src]

Creates owned data from borrowed data, usually by cloning. Read more

pub fn clone_into(&self, target: &mut T)[src]

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

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.

pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]

Performs the conversion.

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.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.

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

pub fn vzip(self) -> V