zng_ext_config/json.rs
1use zng_ext_fs_watcher::{WatchFile, WriteFile};
2
3use super::*;
4
5/// Represents a config source that synchronizes with a JSON file.
6pub type JsonConfig = SyncConfig<JsonBackend>;
7
8#[doc(hidden)]
9pub struct JsonBackend;
10impl SyncConfigBackend for JsonBackend {
11 fn read(mut file: WatchFile) -> io::Result<RawConfigMap> {
12 file.json().map_err(Into::into)
13 }
14
15 fn write(file: &mut WriteFile, map: &RawConfigMap) -> io::Result<()> {
16 file.write_json(map, true)
17 }
18}