Struct knightrs::Variable [−][src]
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]
#[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
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]
fn hash<H: Hasher>(&self, h: &mut H)
[src]
pub fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl PartialEq<Variable> 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]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
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]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
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]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,