Skip to main content

nu_protocol/engine/
variable.rs

1use crate::{Span, Type, Value};
2
3#[derive(Clone, Debug)]
4pub struct Variable {
5    pub declaration_span: Span,
6    pub ty: Type,
7    pub mutable: bool,
8    pub const_val: Option<Value>,
9    /// The variable's name (e.g. `$foo`), if it was registered by name in a
10    /// working-set delta.
11    ///
12    /// Set when the name→id mapping is inserted into a scope (see
13    /// [`StateWorkingSet::insert_variable_into_scope`](crate::engine::StateWorkingSet::insert_variable_into_scope)).
14    /// Permanent engine-state variables often leave this as `None` and are still listed by
15    /// `scope variables` via permanent overlay name maps. Locals that never reach permanent
16    /// overlays rely on this field so stack-based collection can recover their names.
17    pub name: Option<Vec<u8>>,
18}
19
20impl Variable {
21    pub fn new(declaration_span: Span, ty: Type, mutable: bool) -> Variable {
22        Self {
23            declaration_span,
24            ty,
25            mutable,
26            const_val: None,
27            name: None,
28        }
29    }
30}