ed_journals/modules/modules_info/
asynchronous.rs

1use std::path::Path;
2
3use thiserror::Error;
4use tokio::fs;
5
6use crate::modules::shared::asynchronous::live_json_file_watcher::LiveJsonFileWatcher;
7pub use crate::modules::shared::asynchronous::live_json_file_watcher::LiveJsonFileWatcherError as ModulesInfoFileWatcherError;
8use crate::modules_info::models::modules_info::ModulesInfo;
9
10pub type ModulesInfoFileWatcher = LiveJsonFileWatcher<ModulesInfo>;
11
12pub async fn read_modules_info_file<P: AsRef<Path>>(
13    path: P,
14) -> Result<ModulesInfo, ReadModulesInfoFileError> {
15    Ok(serde_json::from_str(&fs::read_to_string(path).await?)?)
16}
17
18#[derive(Debug, Error)]
19pub enum ReadModulesInfoFileError {
20    #[error(transparent)]
21    IO(#[from] std::io::Error),
22
23    #[error("Failed to parse modules info file: {0}")]
24    SerdeJson(#[from] serde_json::Error),
25}