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>

source

pub fn stack( config: &'g Config<'g>, variables: VariableSource<'g>, owner: &'l str, group: &'l str, mode: Mode ) -> Self

Constructs a new stack

source

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

source

pub fn put_owner(&mut self, owner: &'l str)

Changes the owner in the current scope

source

pub fn put_group(&mut self, group: &'l str)

Changes the group in the current scope

source

pub fn owner(&self) -> &'l str

Returns the owner in the current scope

source

pub fn group(&self) -> &'l str

Returns the group in the current scope

source

pub fn mode(&self) -> Mode

Returns the UNIX permissions set for the current scope

source

pub fn variables(&self) -> &VariableSource<'l>

Provides access to variables in the current scope

source

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)

source

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§

source§

impl Display for StackFrame<'_, '_, '_>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more