pub struct Output { /* private fields */ }
Expand description
Interface for the Rego output.
Outputs can either be examined as strings, or inspected using Rego Nodes. It is also possible to extract bindings for specific variables.
§Examples
match result.to_str() {
Ok(output_str) => {
println!("{}", output_str);
}
Err(err_str) => {
println!("error: {}", err_str);
}
}
let x = result.binding("x").expect("cannot get x");
println!("x = {}", x.json().unwrap());
Implementations§
source§impl Output
impl Output
sourcepub fn ok(&self) -> bool
pub fn ok(&self) -> bool
Returns whether the output is ok.
The output of a successful query will always be a Node. However, if there
was an error that arose with the Rego engine, then this Node will be of
kind NodeKind::ErrorSeq
and contain one or more errors. This method
gives a quick way, without inspecting the result node, of finding whether
it is ok.
sourcepub fn to_str(&self) -> Result<&str, &str>
pub fn to_str(&self) -> Result<&str, &str>
Returns the output as a JSON-encoded string.
If the result of Self::ok()
is false, the result will be an string
containing error information.
sourcepub fn to_node(&self) -> Result<Node, Node>
pub fn to_node(&self) -> Result<Node, Node>
Returns the output node.
The value of the Result
enum will reflect the output of
Self::ok()
.
sourcepub fn binding_at_index(
&self,
index: regoSize,
name: &str,
) -> Result<Node, Node>
pub fn binding_at_index( &self, index: regoSize, name: &str, ) -> Result<Node, Node>
Attempts to return the binding for the given variable name.
If the output is not OK or the variable is not bound, then
this will return an Result::Err
with the output node.
Otherwise it will return the bound value for the variable.
sourcepub fn binding(&self, name: &str) -> Result<Node, Node>
pub fn binding(&self, name: &str) -> Result<Node, Node>
Attempts to return the binding for the given variable name.
If the output is not OK or the variable is not bound, then
this will return an Result::Err
with the output node.
Otherwise it will return the bound value for the variable.
sourcepub fn expressions_at_index(&self, index: regoSize) -> Result<Node, Node>
pub fn expressions_at_index(&self, index: regoSize) -> Result<Node, Node>
Attempts to return the expressions at a given result index.
sourcepub fn expressions(&self) -> Result<Node, Node>
pub fn expressions(&self) -> Result<Node, Node>
Attempts to return the expressions at a given result index.