Skip to content

Commit b16e0ca

Browse files
authored
Merge branch 'mehcode:master' into master
2 parents fb5e297 + e3c1d0b commit b16e0ca

File tree

9 files changed

+113
-27
lines changed

9 files changed

+113
-27
lines changed

.github/workflows/external-types.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
- name: Install toolchain
1414
uses: dtolnay/rust-toolchain@master
1515
with:
16-
toolchain: nightly-2023-10-10
16+
toolchain: nightly-2024-02-07
1717

1818
- name: Install cargo-check-external-types
1919
run: cargo install --locked cargo-check-external-types

Cargo.lock

Lines changed: 70 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ maintenance = { status = "actively-developed" }
1717
[features]
1818
default = ["toml", "json", "yaml", "ini", "ron", "json5", "jsonc", "convert-case", "async"]
1919
json = ["serde_json"]
20-
yaml = ["yaml-rust"]
20+
yaml = ["yaml-rust2"]
2121
ini = ["rust-ini"]
2222
json5 = ["json5_rs", "serde/derive"]
2323
jsonc = ["jsonc-parser"]
@@ -33,7 +33,7 @@ nom = "7"
3333
async-trait = { version = "0.1", optional = true }
3434
toml = { version = "0.8", optional = true }
3535
serde_json = { version = "1.0", optional = true }
36-
yaml-rust = { version = "0.4", optional = true }
36+
yaml-rust2 = { version = "0.8", optional = true }
3737
rust-ini = { version = "0.20", optional = true }
3838
ron = { version = "0.8", optional = true }
3939
json5_rs = { version = "0.4", optional = true, package = "json5" }

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
[JSON]: https://github.com/serde-rs/json
2020
[TOML]: https://github.com/toml-lang/toml
21-
[YAML]: https://github.com/chyh1990/yaml-rust
21+
[YAML]: https://github.com/Ethiraric/yaml-rust2
2222
[INI]: https://github.com/zonyitoo/rust-ini
2323
[RON]: https://github.com/ron-rs/ron
2424
[JSON5]: https://github.com/callum-oakley/json5-rs

src/file/format/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pub enum FileFormat {
4343
#[cfg(feature = "json")]
4444
Json,
4545

46-
/// YAML (parsed with yaml_rust)
46+
/// YAML (parsed with yaml_rust2)
4747
#[cfg(feature = "yaml")]
4848
Yaml,
4949

src/file/format/yaml.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::error::Error;
22
use std::fmt;
33
use std::mem;
44

5-
use yaml_rust as yaml;
5+
use yaml_rust2 as yaml;
66

77
use crate::format;
88
use crate::map::Map;

tests/file_yaml.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,7 @@ fn test_error_parse() {
8585
assert_eq!(
8686
res.unwrap_err().to_string(),
8787
format!(
88-
"while parsing a block mapping, did not find expected key at \
89-
line 2 column 1 in {}",
88+
"simple key expect ':' at byte 21 line 3 column 1 in {}",
9089
path_with_extension.display()
9190
)
9291
);

tests/legacy/file_yaml.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,7 @@ fn test_error_parse() {
8585
assert_eq!(
8686
res.unwrap_err().to_string(),
8787
format!(
88-
"while parsing a block mapping, did not find expected key at \
89-
line 2 column 1 in {}",
88+
"simple key expect ':' at byte 21 line 3 column 1 in {}",
9089
path_with_extension.display()
9190
)
9291
);

tests/ron_enum.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
#[derive(Debug, Deserialize)]
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

Comments
 (0)