Context

Struct Context 

Source
pub struct Context<'call> { /* private fields */ }
Expand description

Context for the call to a helper exposes immutable access to the arguments and hash parameters.

It also provides some useful functions for asserting on argument arity and type.

Implementations§

Source§

impl<'call> Context<'call>

Source

pub fn name(&self) -> &str

Get the name for the call.

Source

pub fn arguments(&self) -> &Vec<Value>

Get the list of arguments.

Source

pub fn parameters(&self) -> &Map<String, Value>

Get the map of hash parameters.

Source

pub fn get(&self, index: usize) -> Option<&Value>

Get an argument at an index.

Source

pub fn param(&self, name: &str) -> Option<&Value>

Get a hash parameter for the name.

Source

pub fn get_fallback(&self, index: usize) -> Option<&Value>

Get an argument at an index and use a fallback string value when the argument is missing.

Source

pub fn param_fallback(&self, name: &str) -> Option<&Value>

Get a hash parameter for the name and use a fallback string value when the parameter is missing.

Source

pub fn missing(&self, index: usize) -> Option<&Value>

Get the value for a missing argument.

When the value for an argument is missing it is coerced to Value::Null; this function allows a helper to distinguish between a literal null value and a null resulting from a missing value.

Source

pub fn missing_param(&self, name: &str) -> Option<&Value>

Get the value for a missing parameter.

When the value for a parameter is missing it is coerced to Value::Null; this function allows a helper to distinguish between a literal null value and a null resulting from a missing value.

Source

pub fn call(&self) -> &'call Call<'call>

Get the call syntax tree element.

Source

pub fn raw(&self, index: usize) -> Option<&str>

Get the raw string value for an argument at an index.

Source

pub fn raw_param(&self, name: &str) -> Option<&str>

Get the raw string value for a hash parameter with the given name.

Source

pub fn try_get(&self, index: usize, kinds: &[Type]) -> HelperResult<&Value>

Get an argument at an index and assert that the value is one of the given types.

If no argument exists at the given index the value is treated as null and type assertion is performed on the null value.

Source

pub fn try_param(&self, name: &str, kinds: &[Type]) -> HelperResult<&Value>

Get a hash parameter for the name and assert that the value is one of the given types.

If no parameter exists for the given name the value is treated as null and type assertion is performed on the null value.

Source

pub fn try_value<'a>( &self, value: &'a Value, kinds: &[Type], ) -> HelperResult<&'a Value>

Assert that a value is one of the given kinds.

Source

pub fn text(&self) -> &Option<&'call str>

Get the text for this context.

Only available when invoked as a raw block.

Source

pub fn property(&self) -> &Option<Property>

Get a resolved property.

Only available to blockHelperMissing handlers.

Source

pub fn arity(&self, range: Range<usize>) -> HelperResult<()>

Assert that the call arguments have a valid arity.

If the range start and end are equal than an exact number of arguments are expected and a more concise error message is used. Range ends are inclusive so 0..1 indicates zero or one arguments are allowed.

Source

pub fn assert(&self, value: &Value, kinds: &[Type]) -> HelperResult<()>

Assert on the type of a value.

Source

pub fn assert_block<'a>( &self, template: Option<&'a Node<'a>>, ) -> HelperResult<&'a Node<'a>>

Map an optional template to a result.

If the template is None this will yield an error; use this to assert when an inner block template is required.

Source

pub fn assert_statement<'a>( &self, template: Option<&'a Node<'a>>, ) -> HelperResult<()>

Assert that a block template is empty.

Helpers that do not accept inner block templates can call this to ensure that they are not invoked with the block syntax.

Source

pub fn lookup<'a, S: AsRef<str>>( &self, target: &'a Value, field: S, ) -> Option<&'a Value>

Lookup a field of a value.

If the target value is not an object or array then this will yield None.

Source

pub fn is_truthy(&self, value: &Value) -> bool

Determine if a value is truthy.

Auto Trait Implementations§

§

impl<'call> Freeze for Context<'call>

§

impl<'call> RefUnwindSafe for Context<'call>

§

impl<'call> Send for Context<'call>

§

impl<'call> Sync for Context<'call>

§

impl<'call> Unpin for Context<'call>

§

impl<'call> UnwindSafe for Context<'call>

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.