cargo_openvm/
util.rs

1use std::{
2    fs::read_to_string,
3    path::{Path, PathBuf},
4};
5
6use eyre::Result;
7use openvm_sdk::config::{AppConfig, SdkVmConfig};
8use serde::de::DeserializeOwned;
9
10use crate::default::default_app_config;
11
12pub(crate) fn read_to_struct_toml<T: DeserializeOwned>(path: &PathBuf) -> Result<T> {
13    let toml = read_to_string(path.as_ref() as &Path)?;
14    let ret = toml::from_str(&toml)?;
15    Ok(ret)
16}
17
18pub fn read_config_toml_or_default(config: &PathBuf) -> Result<AppConfig<SdkVmConfig>> {
19    if config.exists() {
20        read_to_struct_toml(config)
21    } else {
22        println!(
23            "{:?} not found, using default application configuration",
24            config
25        );
26        Ok(default_app_config())
27    }
28}