Struct diskplan_traversal::StackFrame
source · pub struct StackFrame<'g, 'p, 'l>where
'g: 'p,
'p: 'l,{
pub config: &'g Config<'g>,
/* private fields */
}
Expand description
Keeps track of variables and provides access to definitions from parent nodes
Example:
use diskplan_schema::DirectorySchema;
use diskplan_traversal::{StackFrame, VariableSource};
// The stack lifetimes allow us to have a function that takes a stack...
fn __<'g>(stack: &StackFrame<'g, '_, '_>, d: &'g DirectorySchema) {
// ...provides access to items referenced by parent scopes...
let var = stack.lookup(&"variable".into()).unwrap();
// ...can be extended with a mutable local scope...
let mut local = stack.push(VariableSource::Directory(d));
// ...and capture local modifications...
let owner = "root";
local.put_owner(owner);
}
Fields§
§config: &'g Config<'g>
A reference to the shared config
Implementations§
source§impl<'g, 'p, 'l> StackFrame<'g, 'p, 'l>
impl<'g, 'p, 'l> StackFrame<'g, 'p, 'l>
sourcepub fn stack(
config: &'g Config<'g>,
variables: VariableSource<'g>,
owner: &'l str,
group: &'l str,
mode: Mode
) -> Self
pub fn stack( config: &'g Config<'g>, variables: VariableSource<'g>, owner: &'l str, group: &'l str, mode: Mode ) -> Self
Constructs a new stack
sourcepub fn push<'s, 'r>(
&'s self,
variables: VariableSource<'g>
) -> StackFrame<'g, 'r, 'r>where
'g: 'r,
's: 'r,
pub fn push<'s, 'r>( &'s self, variables: VariableSource<'g> ) -> StackFrame<'g, 'r, 'r>where 'g: 'r, 's: 'r,
Adds a new scope onto the stack, returning it
sourcepub fn variables(&self) -> &VariableSource<'l>
pub fn variables(&self) -> &VariableSource<'l>
Provides access to variables in the current scope
sourcepub fn lookup<'a>(&'a self, var: &Identifier<'a>) -> Option<Value<'a>>
pub fn lookup<'a>(&'a self, var: &Identifier<'a>) -> Option<Value<'a>>
Looks up the value of a variable in the current or parent scope(s)
sourcepub fn find_definition<'a>(
&self,
var: &Identifier<'a>
) -> Option<&'a SchemaNode<'g>>
pub fn find_definition<'a>( &self, var: &Identifier<'a> ) -> Option<&'a SchemaNode<'g>>
Looks up the definition of a sub-schema in the current or parent scope(s)
Trait Implementations§
Auto Trait Implementations§
impl<'g, 'p, 'l> !RefUnwindSafe for StackFrame<'g, 'p, 'l>
impl<'g, 'p, 'l> !Send for StackFrame<'g, 'p, 'l>
impl<'g, 'p, 'l> !Sync for StackFrame<'g, 'p, 'l>
impl<'g, 'p, 'l> Unpin for StackFrame<'g, 'p, 'l>
impl<'g, 'p, 'l> !UnwindSafe for StackFrame<'g, 'p, 'l>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more