ron icon indicating copy to clipboard operation
ron copied to clipboard

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

Open Diggsey opened this issue 7 years ago • 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.

Diggsey avatar Dec 13 '18 01:12 Diggsey

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 .

torkleyy avatar Dec 13 '18 13:12 torkleyy

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.)

Boscop avatar Feb 26 '20 00:02 Boscop

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

github-actions[bot] avatar Nov 18 '21 15:11 github-actions[bot]

activity

torkleyy avatar Dec 25 '21 20:12 torkleyy

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.

Kulasko avatar Jan 01 '22 05:01 Kulasko

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.

juntyr avatar Jan 06 '22 15:01 juntyr

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.)

tiye avatar May 20 '22 06:05 tiye