Skip to content

ron Deserialize fails with enum with named fields #540

@cBournhonesque

Description

@cBournhonesque

Hi,
I'm not sure why but i cannot get enums working with ron.

My test file:

#![cfg(feature = "ron")]

use serde_derive::Deserialize;
use config::{Config, File, FileFormat};

#[derive(Debug, Deserialize)]
enum A {
    VariantA{ port: u16 },
}

#[derive(Debug, Deserialize)]
struct Settings {
    a: A,
}

fn make() -> Config {
    Config::builder()
        .add_source(File::new("tests/test.ron", FileFormat::Ron))
        .build()
        .unwrap()
}

#[test]
fn test_myron() {
    let c = make();

    // Deserialize the entire file as single struct
    let s: Settings = c.try_deserialize().unwrap();

    dbg!(&s);
}

My config file:

(
    a: VariantA(port: 5000)
)

I get the error:

thread 'test_myron' panicked at tests/test_ron.rs:28:43:
called `Result::unwrap()` on an `Err` value: enum A does not have variant constructor port
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

even though serializing the Settings manually to ron gives the same string

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions