@@ -10,32 +10,58 @@ The design goals of this project were are as follows:
1010 * Sandbox'ed in such a way that only specific values can be bound
1111 * Can be used as a wasm depenedency (or other ffi)
1212
13- While Google's CEL spec was designed around the protobuf message,
14- I decided to focus on using the JSON message instead (CEL spec specifies
15- how to convert from JSON to CEL types).
16-
1713The basic example of how to use:
1814``` rust
19- use rscel :: {CelContext , BindContext , serde_json };
15+ use rscel :: {CelContext , BindContext };
2016
2117let mut ctx = CelContext :: new ();
2218let mut exec_ctx = BindContext :: new ();
2319
2420ctx . add_program_str (" main" , " foo + 3" ). unwrap ();
25- exec_ctx . bind_param (" foo" , 3. into ()); // convert to serde_json::Value
21+ exec_ctx . bind_param (" foo" , 3. into ()); // convert to CelValue
22+
23+ let res = ctx . exec (" main" , & exec_ctx ). unwrap (); // CelValue::Int(6)
24+ assert_eq! (res , 6. into ());
25+ ```
26+
27+ As of 0.10.0 binding protobuf messages from the protobuf crate is now available! Given
28+ the following protobuf message:
29+ ``` protobuf
30+
31+ message Point {
32+ int32 x = 1;
33+ int32 y = 2;
34+ }
35+
36+ ```
37+ The following code can be used to evaluate a CEL expression on a Point message:
38+
39+ ``` rust
40+ use rscel :: {CelContext , BindContext };
41+
42+ // currently rscel required protobuf messages to be in a box
43+ let p = Box :: new (protos :: Point :: new ());
44+ p . x = 4 ;
45+ p . y = 5 ;
46+
47+ let mut ctx = CelContext :: new ();
48+ let mut exec_ctx = BindContext :: new ();
49+
50+ ctx . add_program_str (" main" , " p.x + 3" ). unwrap ();
51+ exec_ctx . bind_protobuf_msg (" p" , p );
2652
27- let res = ctx . exec (" main" , & exec_ctx ). unwrap (); // ValueCell::Int(6)
28- assert! ( TryInto :: < i64 > :: try_into ( res ) . unwrap () == 6 );
53+ assert_eq! ( ctx . exec (" main" , & exec_ctx ), 7. into ());
54+
2955```
3056
3157## Current Benchmark Times
3258| Bench Run | Time |
3359| --------------------------| ----------------|
34- | Run One No Binding: | 0.000310S |
35- | Run Many No Binding: | 0.003657S |
36- | Run One With Binding: | 0.000033S |
37- | Run Many With Bindings: | 0.004281S |
38- | Build Many: | 0.002312S |
39- | Build Many With Bindings: | 0.051369S |
60+ | Run One No Binding | 0.000070054S |
61+ | Run Many No Binding | 0.003451698S |
62+ | Run One With Binding | 0.000015177S |
63+ | Run Many With Bindings | 0.004443471S |
64+ | Build Many | 0.006989954S |
65+ | Build Many With Bindings | 0.084859163S |
4066
4167Build status: [ ![ Rust] ( https://github.com/1BADragon/rscel/actions/workflows/rust.yml/badge.svg )] ( https://github.com/1BADragon/rscel/actions/workflows/rust.yml )
0 commit comments