[][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 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 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 exclusive so 1..1 and 1..2 are the same test they will just generate different error messages.

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.