ron-rs/ron

[Question] Add struct name when serialize

Closed this issue · 2 comments

Hi! I'd like to ask you how I can say the ron serializer that it should append the struct name, to help mapping it with some structs.

Context

Take the following Code:

use serde::{Serialize, Deserialize};

pub trait Command {} 

#[derive(Serialize, Deserialize)]
pub struct Bark;
#[derive(Serialize, Deserialize)]
pub struct Jump;

impl Command for Bark {}
impl Command for Jump {}

now if currently ron::to_string(Bark) would produce the same output as ron::to_string(Jump) which is (). May I ask if it's possible to have Bark() and Jump() instead? I couldn't find an option in the docs which enables this. Do I have to implement this on my own?

Yes, that is possible! You can use ron::ser::to_string_pretty(&value, ron::ser::PrettyConfig::new().struct_names(true))

Thank you! It worked! Sorry for the late reply...