Skip to content
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

Conversion between Value and any T: Serialize/Deserialize #140

Open
Tracked by #397
Diggsey opened this issue Dec 13, 2018 · 7 comments
Open
Tracked by #397

Conversion between Value and any T: Serialize/Deserialize #140

Diggsey opened this issue Dec 13, 2018 · 7 comments
Labels
enhancement good first issue Perfect for new contributors

Comments

@Diggsey
Copy link

Diggsey commented Dec 13, 2018

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.

@torkleyy
Copy link
Contributor

torkleyy commented Dec 13, 2018 via email

@torkleyy torkleyy added the easy An issue that's easy to implement label Feb 14, 2019
bors bot added a commit that referenced this issue Feb 19, 2019
146: Implement `Value::into_rust` r=kvark a=torkleyy

Partial fix for #140 

Co-authored-by: Thomas Schaller <torkleyy@gmail.com>
@Boscop
Copy link

Boscop commented Feb 26, 2020

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

srid added a commit to srid/x-cli-scratch that referenced this issue Apr 13, 2021
Switch from ron serde_yaml because of ron-rs/ron#140
@github-actions
Copy link

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 github-actions bot added the stale label Nov 18, 2021
@kvark kvark reopened this Dec 3, 2021
@kvark kvark reopened this Dec 17, 2021
@torkleyy
Copy link
Contributor

activity

@torkleyy torkleyy reopened this Dec 25, 2021
@Kulasko
Copy link

Kulasko commented Jan 1, 2022

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.

@github-actions github-actions bot removed the stale label Jan 1, 2022
@juntyr
Copy link
Member

juntyr commented Jan 6, 2022

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
Copy link

tiye commented May 20, 2022

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

@juntyr juntyr added enhancement good first issue Perfect for new contributors and removed easy An issue that's easy to implement labels Aug 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement good first issue Perfect for new contributors
Projects
None yet
Development

No branches or pull requests

7 participants