Skip to main content

TestFn

Type Alias TestFn 

Source
pub type TestFn = Arc<dyn Fn(&Value, &[String]) -> Result<bool, EngineError> + Send + Sync>;
Expand description

Filter, test and loader extension points. Defined in staticweaver-core and re-exported here at their historical paths. Signature of a user-registered test, as accepted by staticweaver::Engine::add_test. The test receives the operand value the is X predicate is applied to and any extra arguments, and returns a boolean (or an EngineError for malformed inputs). Custom tests override built-ins (defined, empty, none) of the same name.

§Examples

use staticweaver_core::{TestFn, Value};
use std::sync::Arc;

let is_admin: TestFn = Arc::new(|v: &Value, _args: &[String]| {
    Ok(matches!(v, Value::String(s) if s == "admin"))
});
assert!(is_admin(&Value::from("admin"), &[]).unwrap());

Aliased Type§

pub struct TestFn { /* private fields */ }