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

serde-file-value

A Serde deserializer which transparently loads files as string values

1 unstable release

0.1.0 Jun 1, 2024

#867 in Parser implementations

Download history 177/week @ 2024-05-29 173/week @ 2024-06-05 265/week @ 2024-06-12 188/week @ 2024-06-19 170/week @ 2024-06-26 183/week @ 2024-07-03 238/week @ 2024-07-10 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 261/week @ 2024-08-28

1,102 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

~110–345KB