ron icon indicating copy to clipboard operation
ron copied to clipboard

Support (basic) attributes

Open voidentente opened this issue 2 years ago • 2 comments

I think it would be more in line with the Rust style of things if doc comments would be treated as parseable attributes by ron, like in Rust.

Of course, Value would have to be extended into something maybe looking like this:

pub enum Value {
    Bool(Field<bool>),
    Char(Field<char>),
    Map(Field<Map>),
    Number(Field<Number>),
    Option(Field<Option<Box<Value>>>),
    String(Field<String>),
    Seq(Field<Vec<Value>>),
    Unit,
}

pub struct Field<T> {
    attrs: Vec<Attr>
    value: T,
}

voidentente avatar Jan 20 '23 17:01 voidentente

I think adding support for doc comments is definitely a neat idea and could help with the question of how to preserve comments across serde - here doc comments would be given a special role in that we would guarantee to keep them around. How this could be achieved for Value and when going through other serde formats would be a bit more difficult and might require some slight hacks such as using special struct names. One more thought that comes to mind is that our Value type is asking more and more to become an AST so that it can express all of RON (almost) losslessly (unfortunately serde’s model is not expressive enough to support fully lossless round trips through RON, Value, and other formats).

juntyr avatar Jan 23 '23 10:01 juntyr

I've made a little non-intrusive PR for supporting serialization of metadata, see https://github.com/ron-rs/ron/pull/544

voidentente avatar Aug 05 '24 20:08 voidentente