ron icon indicating copy to clipboard operation
ron copied to clipboard

I don't see any Enum

Open spielcrypto opened this issue 5 months ago • 6 comments

I have this file .ron:

Price(
    model: Model(
        A(0.02),
        B(0.094),
        C(0.05),
        D(0.02),
        E(0.004),
        F(0.001),

    ),
    tool: Tool(
        A(0.006),
        B(0.3),
    )
)

but I don't know if this will work like this:

#[derive(Debug, Deserialize)]
struct Price {
  model: Model,
  tool: Tool
}

#[derive(Debug, Deserialize)]
enum Model {
  A(f64),
  B(f64),
  C(f64)
  D(f64),
  E(f64),
  F(f64)
}

#[derive(Debug, Deserialize)]
enum Model {
  A(f64),
  B(f64)
}

I didn't see examples about enum

spielcrypto avatar Jul 06 '25 11:07 spielcrypto

I think if I'm not wrong the .ron file should be like this:

Price(
    model: [
        A(0.02),
        B(0.094),
        C(0.05),
        D(0.02),
        E(0.004),
        F(0.001),
    ],
    tool: [
        A(0.006),
        B(0.3),
    ]
)

and deserialization like this:

#[derive(Debug, Deserialize)]
struct Price {
  model: Vec<Model>,
  tool: Vec<Tool>
}

#[derive(Debug, Deserialize)]
enum Model {
  A(f64),
  B(f64),
  C(f64)
  D(f64),
  E(f64),
  F(f64)
}

#[derive(Debug, Deserialize)]
enum Model {
  A(f64),
  B(f64)
}

spielcrypto avatar Jul 06 '25 11:07 spielcrypto

Yes, I think your second version is correct and should work

juntyr avatar Jul 06 '25 17:07 juntyr

yes it works, thanks and great job for this text format!

spielcrypto avatar Jul 08 '25 06:07 spielcrypto

Can we reopen this? the format for enums is somehow still not documented anywhere I can find.

rkanati avatar Nov 17 '25 00:11 rkanati

@rkanati What examples would you like to see?

juntyr avatar Nov 17 '25 04:11 juntyr

Just literally any example of what an enum looks like in ron in the rustdocs.

rkanati avatar Nov 17 '25 10:11 rkanati