ron-rs/ron

Conversion between `Value` and any `T: Serialize/Deserialize`

Opened this issue · 7 comments

Take a look at serde_json::from_value and serde_json::to_value - these functions would exactly mirror that.

RON has the unique opportunity to be an "impartial" serialization format for storing structured data internally in rust programs, so that it can still be converted to other formats without having to know the original type, but to do that, you need a way to go from arbitrary rust types to a RON value, and vice versa.

Yes, please add a to_value function! I need this for my use-case. (I'm dealing with large instances, and going through string is less efficient.)

(And Value::into_rust should be renamed to from_value.)

Issue has had no activity in the last 180 days and is going to be closed in 7 days if no further activity occurs

activity

Please please can we have this? I am using partial serialization/deserialization for automatic upgrading of file types and I really want support for a better format as JSON. The TOML crate doesn't support enums and tuples, so I arrived here. Having the functions like suggested by @Diggsey would make that use case oh so much more painless.

I think serializing into the Value type really isn't an issue. The problem is maintaining all type information throughout the process. While serde's JSON tricks can be applied to get Rust -> RON -> Value -> Rust to work (see #357 (comment)), Rust -> Value -> Rust would probably require some extra variants in Value so it can also survive Rust -> Value -> RON -> Value -> Rust. The Number type should probably also be expanded to parse::AnyNum so any Rust number can be stored losslessly.

tiye commented

can we add our own glue code to have to_value based on existing public functions? doesn't look like a core feature ron going to provide, but useful in some cases of data conversion.

(looked at code again, current serializer outputs to io::Writer... well not a simple task.)