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>
impl<'call> Context<'call>
Sourcepub fn parameters(&self) -> &Map<String, Value>
pub fn parameters(&self) -> &Map<String, Value>
Get the map of hash parameters.
Sourcepub fn get_fallback(&self, index: usize) -> Option<&Value>
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.
Sourcepub fn param_fallback(&self, name: &str) -> Option<&Value>
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.
Sourcepub fn missing(&self, index: usize) -> Option<&Value>
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.
Sourcepub fn missing_param(&self, name: &str) -> Option<&Value>
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.
Sourcepub fn raw(&self, index: usize) -> Option<&str>
pub fn raw(&self, index: usize) -> Option<&str>
Get the raw string value for an argument at an index.
Sourcepub fn raw_param(&self, name: &str) -> Option<&str>
pub fn raw_param(&self, name: &str) -> Option<&str>
Get the raw string value for a hash parameter with the given name.
Sourcepub fn try_get(&self, index: usize, kinds: &[Type]) -> HelperResult<&Value>
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.
Sourcepub fn try_param(&self, name: &str, kinds: &[Type]) -> HelperResult<&Value>
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.
Sourcepub fn try_value<'a>(
&self,
value: &'a Value,
kinds: &[Type],
) -> HelperResult<&'a Value>
pub fn try_value<'a>( &self, value: &'a Value, kinds: &[Type], ) -> HelperResult<&'a Value>
Assert that a value is one of the given kinds.
Sourcepub fn text(&self) -> &Option<&'call str>
pub fn text(&self) -> &Option<&'call str>
Get the text for this context.
Only available when invoked as a raw block.
Sourcepub fn property(&self) -> &Option<Property>
pub fn property(&self) -> &Option<Property>
Get a resolved property.
Only available to blockHelperMissing handlers.
Sourcepub fn arity(&self, range: Range<usize>) -> HelperResult<()>
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.
Sourcepub fn assert(&self, value: &Value, kinds: &[Type]) -> HelperResult<()>
pub fn assert(&self, value: &Value, kinds: &[Type]) -> HelperResult<()>
Assert on the type of a value.
Sourcepub fn assert_block<'a>(
&self,
template: Option<&'a Node<'a>>,
) -> HelperResult<&'a Node<'a>>
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.
Sourcepub fn assert_statement<'a>(
&self,
template: Option<&'a Node<'a>>,
) -> HelperResult<()>
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.