Open obsoleszenz opened 1 month ago
This is not supported today. I believe the cel-go project supports this via protobufs. It's definitely something that we need to support to be spec-compliant.
Is there a easy way to hack this so that in addition to Json, we also support Ron ? That might be a solution to this.
Context: I am currently using Ron for my config files -- but I find what I really want is not merely Ron, but EXPRESSIONS over Ron -- which led me to finding Cel. And I'm now wondering if there is a easy hack to make Cel-rust also support Ron in addition to Json for the data notation.
@zeroexcuses any type that implements Serialize
(which a Rust ron rust would) can be added as a variable to the context. Not every rust data type is supported (tuples for example), so those wouldn't be available in your expressions, but the CEL-supported types should work fine.
Are you having issues doing the following? Or is your question about deserializing from CEL to Ron?
use serde::{Deserialize, Serialize};
#[derive(Debug, Deserialize, Serialize)]
struct MyStruct {
boolean: bool,
float: f32,
}
let x: MyStruct = ron::from_str("(boolean: true, float: 1.23)").unwrap();
let mut context = Context::default();
context.add_variable("x", x).unwrap();
Is there a easy way to hack this so that in addition to Json, we also support Ron ? That might be a solution to this.
Context: I am currently using Ron for my config files -- but I find what I really want is not merely Ron, but EXPRESSIONS over Ron -- which led me to finding Cel. And I'm now wondering if there is a easy hack to make Cel-rust also support Ron in addition to Json for the data notation.
This is also what i want/need. I started hacking expressions into my rust types, which kinda works but also is hacky. I think fusing cel and the ron syntax for enums/structs would be quite neat. I could imagine that one could return strings from cel and then deserialize them on the rust side to get rust types. Maybe that's the hack you are looking for?
Can you help me understand the idea behind coupling Ron and cel? Cel is format-agnostic. Anything that implements serialize can be referenced in a CEL expression already.
Can you help me understand the idea behind coupling Ron and cel? Cel is format-agnostic. Anything that implements serialize can be referenced in a CEL expression already.
I'm more talking about deserializing. Being able to construct rust structs/enums from cel would be amazing and leveraging the ron syntax for this.
From the cle doc it seems like it's possible to construct strongly typed types inside cel and pass them back. Does cel-rust support this? Couldn't find documentation about this.
Example: