We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent c2fe079 commit 7cfc959Copy full SHA for 7cfc959
tests/ron_enum.rs
@@ -0,0 +1,35 @@
1
+use config::{Config, File, FileFormat};
2
+use serde_derive::Deserialize;
3
+
4
+#[derive(Debug, Deserialize)]
5
+#[serde(untagged)]
6
+enum A {
7
+ VariantA { port: u16 },
8
+}
9
10
11
+struct Settings {
12
+ a: A,
13
14
15
+#[test]
16
+fn test_ron_enum() {
17
+ let c = Config::builder()
18
+ .add_source(File::from_str(
19
+ r#"
20
+ (
21
+ a: VariantA ( port: 5000 )
22
+ )
23
+ "#,
24
+ FileFormat::Ron,
25
+ ))
26
+ .build()
27
+ .unwrap();
28
29
+ // Deserialize the entire file as single struct
30
+ let s = c.try_deserialize::<Settings>();
31
+ assert!(s.is_ok(), "Not Ok(_): {}", s.unwrap_err());
32
+ let s = s.unwrap();
33
+ let A::VariantA { port } = s.a;
34
+ assert_eq!(port, 5000);
35
0 commit comments