-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Build on previous commits to define extract(_inner)_lossy.
These functions behave the same as extract(_inner), but they accept appropriate strings and numbers in places of booleans, and appropriate strings in place of numbers.
- Loading branch information
1 parent
cc06d4d
commit 524f2e0
Showing
3 changed files
with
133 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
use serde::Deserialize; | ||
use figment::{Figment, providers::{Toml, Format}}; | ||
|
||
#[derive(Debug, Deserialize, PartialEq)] | ||
struct Config { | ||
bs: Vec<bool>, | ||
u8s: Vec<u8>, | ||
i32s: Vec<i32>, | ||
f64s: Vec<f64>, | ||
} | ||
|
||
static TOML: &str = r##" | ||
u8s = [1, 2, 3, "4", 5, "6"] | ||
i32s = [-1, -2, 3, "-4", 5, "6"] | ||
f64s = [1, "2", -3, -4.5, "5.0", "-6.0"] | ||
bs = [true, false, "true", "false", "YES", "no", "on", "OFF", "1", "0", 1, 0] | ||
"##; | ||
|
||
#[test] | ||
fn lossy_values() { | ||
let config: Config = Figment::from(Toml::string(TOML)).extract_lossy().unwrap(); | ||
assert_eq!(&config.u8s, &[ 1, 2, 3, 4, 5, 6 ]); | ||
assert_eq!(&config.i32s, &[-1, -2, 3, -4, 5, 6]); | ||
assert_eq!(&config.f64s, &[1.0, 2.0, -3.0, -4.5, 5.0, -6.0]); | ||
assert_eq!(&config.bs, &[ | ||
true, false, true, false, true, false, true, false, true, false, true, false | ||
]); | ||
} |