pub struct Scope<'a> { /* private fields */ }Expand description
An evaluation scope: a data model plus the collection context bindings resolve against.
The root scope resolves relative paths from /. Entering a template item
with Scope::item pushes the item’s pointer as the new base and records
the iteration index for @index.
Implementations§
Source§impl<'a> Scope<'a>
impl<'a> Scope<'a>
Sourcepub fn index(&self) -> Option<usize>
pub fn index(&self) -> Option<usize>
The iteration index, when this scope is a collection item.
Sourcepub fn item(&self, collection_path: &str, index: usize) -> Scope<'a>
pub fn item(&self, collection_path: &str, index: usize) -> Scope<'a>
Descends into element index of the collection at collection_path.
collection_path is itself resolved through this scope, so nested
templates compose.
Sourcepub fn resolve_pointer(&self, path: &str) -> String
pub fn resolve_pointer(&self, path: &str) -> String
Turns an A2UI path (absolute or relative) into an absolute JSON Pointer.
The empty path and / both denote the whole data model.
Sourcepub fn resolve(&self, path: &str) -> Option<&'a Value>
pub fn resolve(&self, path: &str) -> Option<&'a Value>
Resolves a path to a value in the data model, or None if absent.
Sourcepub fn resolve_string(&self, path: &str) -> String
pub fn resolve_string(&self, path: &str) -> String
Resolves a path and stringifies the result.
Sourcepub fn resolve_dynamic(&self, value: &Value) -> Result<Value>
pub fn resolve_dynamic(&self, value: &Value) -> Result<Value>
Resolves a DynamicValue: a literal, a {"path": ...} binding, or a
{"call": ..., "args": ...} function call.
Objects and arrays are walked recursively so nested bindings inside an
action context resolve too.
§Errors
Returns Error::Binding if a formatString template is malformed or
names a function this crate cannot evaluate.
Sourcepub fn resolve_dynamic_with(
&self,
value: &Value,
functions: &dyn FunctionResolver,
) -> Result<Value>
pub fn resolve_dynamic_with( &self, value: &Value, functions: &dyn FunctionResolver, ) -> Result<Value>
Scope::resolve_dynamic with catalog functions supplied by the caller.
§Errors
Sourcepub fn format_string(&self, template: &str) -> Result<String>
pub fn format_string(&self, template: &str) -> Result<String>
Interpolates a formatString template against this scope.
Expressions are written ${...} and may contain an absolute path
(${/user/name}), a relative path (${name}), a literal, a nested
${...}, or a function call (${@index(offset: 1)}). A literal ${ is
written \${.
§Errors
Returns Error::Binding for an unterminated expression, trailing
characters after an expression, or a function this crate cannot evaluate.
Sourcepub fn format_string_with(
&self,
template: &str,
functions: &dyn FunctionResolver,
) -> Result<String>
pub fn format_string_with( &self, template: &str, functions: &dyn FunctionResolver, ) -> Result<String>
Scope::format_string with catalog functions supplied by the caller.
§Errors
See Scope::format_string.