-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: Added a Serializer implementation for Values * feat: Testing * feat: Added exists and exists_one macros * refactor: Map testing without CEL * feat: Added tests for exist and exists_one macros * refactor: Addressed Error handling and implemented TryIntoValue trait * feat: Introducing add_variable_from_value
- Loading branch information
Showing
11 changed files
with
1,027 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use cel_interpreter::{to_value, Context, Program}; | ||
use serde::Serialize; | ||
|
||
// An example struct that derives Serialize | ||
#[derive(Serialize)] | ||
struct MyStruct { | ||
a: i32, | ||
b: i32, | ||
} | ||
|
||
fn main() { | ||
let program = Program::compile("foo.a == foo.b").unwrap(); | ||
let mut context = Context::default(); | ||
|
||
// MyStruct will be implicitly serialized into the CEL appropriate types | ||
context | ||
.add_variable("foo", MyStruct { a: 1, b: 1 }) | ||
.unwrap(); | ||
// To explicitly serialize structs use to_value() | ||
let _cel_value = to_value(MyStruct { a: 2, b: 2 }).unwrap(); | ||
|
||
let value = program.execute(&context).unwrap(); | ||
assert_eq!(value, true.into()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.