Closed jplock closed 7 months ago
I think we just need to implement Serialize for Value in order for this to work, which has the added advantage of not being strictly tied to JSON. I'll take a look at this this weekend. I apologize for the delay -- been a crazy week.
Would another approach be to implement Display for Value
?
@jplock you certainly could, though as a library, it would require you to assume that your users always want to serialize to a specific format (whatever format we serialize to in the Display trait implementation). That is probably not a safe assumption. The better approach would be to implement serde::Serialize
for Value
, that way you can use any serde-compatible serializer. In your case, you would use serde_json to serialize Value to a JSON string.
I've gone ahead and done this in the serialize-value
branch. Please experiment and provide feedback by pointing your cargo dependency to this repo and branch. Something like this should work
[dependencies]
cel-interpreter = { git = "https://github.com/clarkmcc/cel-rust", branch = "serialize-value", path = "interpreter" }
This is working, thank you! I'm using serde_json::to_value(value)
Latest release 0.7.0 contains support for serializing values
I’m fairly new to Rust and am using this project. I’d like to convert the executed Value into a String so I can serialize it to JSON.
Does Value need to implement From for this to work?