Skip to main content

Crate bel

Crate bel 

Source
Expand description

Better Expression Language (BEL), a non-Turing complete expression language designed for simplicity, speed, and safety.

BEL is ideal for lightweight expression evaluation when a scripting language or a WASM module would be too resource intensive.

jwt.exp < now().unix()
path.starts_with("/api") || path.matches(Regex("^/(admin|secret)"))
headers.all(header, header.length() < 256)

§Types

String, Int, Float, Regex, Timestamp, Duration.

§Example

Create and execute a simple BEL expression:

use bel::{Context, Program, Value};

let program = Program::compile("add(40, 2) == 42").unwrap();
let mut context = Context::default();
context.add_function("add", |a: i64, b: i64| a + b);
let value = program.execute(&context).unwrap();
assert_eq!(value, Value::Bool(true));

Re-exports§

pub use common::ast::IdedExpr;
pub use context::Context;
pub use functions::FunctionContext;
pub use objects::ResolveResult;
pub use objects::Value;
pub use parser::ParseError;
pub use parser::ParseErrors;

Modules§

common
context
duration
A signed duration type for the expression language.
extractors
functions
objects
parser

Macros§

impl_conversions
impl_handler

Structs§

Duration
A wrapper Duration type which allows conversion to Value::Duration for types using automatic conversion with serde::Serialize.
Ip
Program
Timestamp
A wrapper Timestamp type which allows conversion to Value::Timestamp for types using automatic conversion with serde::Serialize.

Enums§

ConvertToJsonError
ExecutionError
SerializationError

Functions§

to_value