1 unstable release
0.1.0 | Jun 1, 2024 |
---|
#1543 in Parser implementations
224 downloads per month
Used in 2 crates
(via witchcraft-server)
17KB
441 lines
serde-file-value
A Serde deserializer which transparently loads files as string values.
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
lib.rs
:
A Serde deserializer which transparently loads files as string values.
Usage
Assume we have a /mnt/secrets/my_secret
file that looks like:
hunter2
And a conf/config.json
that looks like:
{
"secret_value": "${file:/mnt/secrets/my_secret}"
}
use std::{fs, io, path::Path};
use serde::Deserialize;
#[derive(Deserialize)]
struct Config {
secret_value: String,
}
let config = fs::read("conf/config.json").unwrap();
let mut deserializer = serde_json::Deserializer::from_slice(&config);
let config: Config = serde_file_value::deserialize(&mut deserializer, |_, _| ()).unwrap();
assert_eq!(config.secret_value, "hunter2");
Dependencies
~105–335KB