nushell/crates/nu-protocol/src/value/evaluate.rs

32 lines
823 B
Rust
Raw Normal View History

2020-05-27 06:50:26 +02:00
use crate::value::Value;
use indexmap::IndexMap;
use serde::{Deserialize, Serialize};
use std::fmt::Debug;
/// An evaluation scope. Scopes map variable names to Values and aid in evaluating blocks and expressions.
/// Additionally, holds the value for the special $it variable, a variable used to refer to the value passing
/// through the pipeline at that moment
#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct Scope {
pub it: Value,
pub vars: IndexMap<String, Value>,
2020-05-06 05:56:31 +02:00
pub env: IndexMap<String, String>,
}
impl Scope {
/// Create an empty scope
2020-05-27 06:50:26 +02:00
pub fn new() -> Scope {
Scope {
2020-05-27 06:50:26 +02:00
it: Value::nothing(),
vars: IndexMap::new(),
2020-05-06 05:56:31 +02:00
env: IndexMap::new(),
}
}
2020-05-27 06:50:26 +02:00
}
2020-05-27 06:50:26 +02:00
impl Default for Scope {
fn default() -> Scope {
Scope::new()
}
}