Struct 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>

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> Freeze for StackFrame<'g, 'p, 'l>

§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where 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.

Source§

impl<T> Instrument for T

Source§

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

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

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 T
where 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 T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

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

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

Source§

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 T
where U: TryFrom<T>,

Source§

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.
Source§

impl<T> WithSubscriber for T

Source§

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
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

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