-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Constructing rust types in cel #73
Comments
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 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(); |
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. |
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. |
There's an important disambiguation to be made here. Ron is a config file format, while it looks like Rust, it doesn't actually define a schema. A schema would allow you to define: MyStruct {
example: Either<String, f32>
} while MyStruct {
example: "I must be a discrete value, even though Either implements Serialize and Deserialize for both types"
} So Building types at runtime requires protobufs, and they will never be visible to the complier. Crates like
|
@Caellian for me it's not about dynamic types. I think defining the schema in rust is the way to go, but allowing the cel side to construct those types. Personally I don't care if protobuf or serde or anything else is used under the hood. |
Oh, I get it now. For now you can get very close by using functions, but I see what you mean. This suggestion then requires extending both the parser and interpreter. The parser is straightforward enough, the interpreter would need a new |
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:
The text was updated successfully, but these errors were encountered: