hatter

Struct Env

Source
pub struct Env { /* private fields */ }
Expand description

Env is the top-level environment in which a Hatter template is evaluated and rendered.

Implementations§

Source§

impl Env

Source

pub fn new() -> Env

New, top-level Env.

Source

pub fn out(&mut self) -> String

Return and clear output.

Source

pub fn empty_args(&mut self) -> Args<'_>

Create an empty Args struct, to call a helper function.

Source

pub fn scope(&self) -> &Scope

Nearest (currently active) scope.

Source

pub fn push_scope(&mut self)

Add a new scope to the stack, which becomes active.

Source

pub fn pop_scope(&mut self)

Kill the active scope.

Source

pub fn mut_scope(&mut self) -> &mut Scope

Nearest (currently active) scope.

Source

pub fn var_exists(&self, key: &str) -> bool

Does a value exist in this or any parent scopes?

Source

pub fn lookup(&self, key: &str) -> Option<Ref<'_, Value>>

Find a value, looking first in the most recently pushed scope.

Source

pub fn set<V: Into<Value>>(&self, key: &str, val: V)

Set a value to the nearest scope.

Source

pub fn update<V: Into<Value>>(&self, key: &str, val: V)

Set a value in a parent scope, or create it in the nearest.

Source

pub fn print<V: Into<Value>>(&mut self, val: V)

Add something to our render buffer without a trailing line.

Source

pub fn render(&mut self, source: &str) -> Result<String>

Render statements into a String.

Source

pub fn block(&mut self, stmts: &[Stmt]) -> Result<Value>

Evaluate a block of statements, returning the last one.

Source

pub fn printed_block(&mut self, stmts: &[Stmt]) -> Result<Value>

Evaluate a block of statements and print what each returns. “Outside of a tag, tags are printed. Inside of a tag, everything is printed.”

Source

pub fn eval_src(&mut self, src: &str) -> Result<Value>

Evaluate source code, returning its Value.

Source

pub fn eval(&mut self, stmt: &Stmt) -> Result<Value>

Evaluate one statement, returning its Value.

Trait Implementations§

Source§

impl Debug for Env

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for Env

Source§

fn default() -> Env

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for Env

§

impl !RefUnwindSafe for Env

§

impl !Send for Env

§

impl !Sync for Env

§

impl Unpin for Env

§

impl !UnwindSafe for Env

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, 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, 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.