ron-rs / ron

Rusty Object Notation
https://docs.rs/ron
Apache License 2.0
3.31k stars 122 forks source link

Would it be possible to make ron 100% Rust-syntax compatible? #501

Open surban opened 1 year ago

surban commented 1 year ago

Maybe this is out of scope for this project, but would it be possible to make the ron format parseable by the Rust compiler? This would resemble how JSON is a 100% valid subset of JavaScript.

This might have interesting applications for code generation, especially in build.rs.

juntyr commented 1 year ago

That's an interesting question for sure. I am hoping to slowly make ron more Rusty (e.g. #438), but there are some design decisions that differ.

Rust code always needs to be verbose in all types, whereas ron is designed to also be compact when all types are known (e.g. by optionally omitting struct names). Therefore, I don't think that every valid ron document will always be valid Rust, but that perhaps in the future there could be a combination of pretty serialisation flags which outputs a Rust-compatible subset of ron.

I think that the most likely avenue could be some small translation layer that takes in a best-effort-Rusty ron string and makes some final tweaks to it.