#load-file #deserializer #transparently #io #json

serde-file-value

A Serde deserializer which transparently loads files as string values

1 unstable release

0.1.0 Jun 1, 2024

#1543 in Parser implementations

Download history 245/week @ 2024-07-17 228/week @ 2024-07-24 273/week @ 2024-07-31 239/week @ 2024-08-07 268/week @ 2024-08-14 286/week @ 2024-08-21 277/week @ 2024-08-28 263/week @ 2024-09-04 368/week @ 2024-09-11 560/week @ 2024-09-18 534/week @ 2024-09-25 481/week @ 2024-10-02 169/week @ 2024-10-09 11/week @ 2024-10-16 7/week @ 2024-10-23 4/week @ 2024-10-30

224 downloads per month
Used in 2 crates (via witchcraft-server)

MIT/Apache

17KB
441 lines

serde-file-value

Documentation

A Serde deserializer which transparently loads files as string values.

License

Licensed under either of

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