[][src]Struct bracket::render::context::Context

pub struct Context<'call> { /* fields omitted */ }

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

impl<'call> Context<'call>[src]

pub fn name(&self) -> &str[src]

Get the name for the call.

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

Get the list of arguments.

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

Get the map of hash parameters.

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

Get an argument at an index.

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

Get a hash parameter for the name.

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

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

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

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

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

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.

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

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.

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

Get the call syntax tree element.

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

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

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

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

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

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.

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

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.

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

Assert that a value is one of the given kinds.

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

Get the text for this context.

Only available when invoked as a raw block.

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

Get a resolved property.

Only available to blockHelperMissing handlers.

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

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.

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

Assert on the type of a value.

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

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.

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

Lookup a field of a value.

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

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

Determine if a value is truthy.

Auto Trait Implementations

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

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.