Struct knightrs::Variable [−][src]
pub struct Variable(_);
Expand description
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]
#[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]
#[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]pub fn assign(&self, value: Value)
[src]
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]
#[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 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> BorrowMut<T> for T where
T: ?Sized,
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]pub fn borrow_mut(&mut self) -> &mut T
[src]
pub fn borrow_mut(&mut self) -> &mut T
[src]Mutably borrows from an owned value. Read more
impl<T> ToOwned for T where
T: Clone,
[src]
impl<T> ToOwned for T where
T: Clone,
[src]type Owned = T
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
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]
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<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,