Conversion between `Value` and any `T: Serialize/Deserialize`
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.
There already is a Deserializer implementation for Value, so this
shouldn't be very hard to implement.
On Thu, Dec 13, 2018, 02:01 Diggory Blake <[email protected] wrote:
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.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/ron-rs/ron/issues/140, or mute the thread https://github.com/notifications/unsubscribe-auth/AWFFucD4Q7BwKgvEamLaYqTgb3mRo25wks5u4acDgaJpZM4ZQu4l .
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 https://github.com/ron-rs/ron/issues/357#issuecomment-1006473301), 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.
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.)