Skip to main content

serde/
serde.rs

1use bel::{Context, Program};
2use serde::Serialize;
3
4// An example struct that derives Serialize
5#[derive(Serialize)]
6struct MyStruct {
7    a: i32,
8    b: i32,
9}
10
11fn main() {
12    let program = Program::compile("foo.a == foo.b").unwrap();
13    let mut context = Context::default();
14
15    // MyStruct will be implicitly serialized into the CEL appropriate types
16    context
17        .add_variable(
18            "foo",
19            MyStruct {
20                a: 1,
21                b: 1,
22            },
23        )
24        .unwrap();
25
26    let value = program.execute(&context).unwrap();
27    assert_eq!(value, true.into());
28}