blob: 5a43a8de9d1b079ed6968d2fe099ef31fa037e42 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
#![cfg(feature = "yaml")]
use rust_decimal::Decimal;
use serde::Deserialize;
use config::{File, FileFormat};
const YAML: &str = r"
foo: 100.0
bar: 200.0
";
#[derive(Debug, Deserialize)]
pub struct Config {
pub foo: Decimal,
pub bar: Option<Decimal>,
}
#[test]
fn test_yaml_decimal() {
let c: Config = config::Config::builder()
.add_source(File::from_str(YAML, FileFormat::Yaml))
.build()
.unwrap()
.try_deserialize()
.expect("Deserialization failed");
assert_eq!(c.foo, Decimal::from(100));
assert_eq!(c.bar, Some(Decimal::from(200)));
}
|