daemon_base/config.rs
1//! Configuration management for the daemon library.
2//!
3//! This module defines the `DaemonConfig` struct, which is used to load and manage
4//! configuration settings for the daemon.
5
6use serde::{Deserialize, Serialize};
7use std::fs;
8
9/// Represents the configuration for the daemon.
10#[derive(Debug, Serialize, Deserialize)]
11pub struct DaemonConfig {
12 /// The log level (e.g., "debug", "info", "warn", "error").
13 pub log_level: String,
14 /// Paths to binaries or resources to load.
15 pub binary_paths: Vec<String>,
16 /// Whether async support is enabled.
17 pub async_enabled: bool,
18}
19
20impl DaemonConfig {
21 /// Loads the configuration from a file.
22 pub fn from_file(path: &str) -> Result<Self, Box<dyn std::error::Error>> {
23 let config_str = fs::read_to_string(path)?;
24 let config: DaemonConfig = serde_json::from_str(&config_str)?;
25 Ok(config)
26 }
27}