pub struct Config {
pub server: ServerConfig,
pub storage: StorageConfig,
pub security: SecurityConfig,
pub devices: Vec<DeviceConfig>,
pub prometheus: PrometheusConfig,
pub mqtt: MqttConfig,
}Expand description
Server configuration.
Fields§
§server: ServerConfigServer settings.
storage: StorageConfigStorage settings.
security: SecurityConfigSecurity settings.
devices: Vec<DeviceConfig>Devices to monitor.
prometheus: PrometheusConfigPrometheus metrics settings.
mqtt: MqttConfigMQTT publisher settings.
Implementations§
Source§impl Config
impl Config
Sourcepub fn load_default() -> Result<Self, ConfigError>
pub fn load_default() -> Result<Self, ConfigError>
Load configuration from the default path.
Sourcepub fn load<P: AsRef<Path>>(path: P) -> Result<Self, ConfigError>
pub fn load<P: AsRef<Path>>(path: P) -> Result<Self, ConfigError>
Load configuration from a file.
Sourcepub fn save<P: AsRef<Path>>(&self, path: P) -> Result<(), ConfigError>
pub fn save<P: AsRef<Path>>(&self, path: P) -> Result<(), ConfigError>
Save configuration to a file.
Sourcepub fn validate(&self) -> Result<(), ConfigError>
pub fn validate(&self) -> Result<(), ConfigError>
Validate the configuration and return any errors.
This checks:
- Server bind address is valid (host:port format)
- Storage path is not empty
- Device addresses are not empty
- Device poll intervals are within reasonable bounds (10s - 1 hour)
- No duplicate device addresses
§Example
use aranet_service::Config;
let config = Config::default();
config.validate().expect("Default config should be valid");Sourcepub fn load_validated<P: AsRef<Path>>(path: P) -> Result<Self, ConfigError>
pub fn load_validated<P: AsRef<Path>>(path: P) -> Result<Self, ConfigError>
Load and validate configuration from a file.
This is a convenience method that combines load() and validate().
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Config
impl<'de> Deserialize<'de> for Config
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for Config
impl RefUnwindSafe for Config
impl Send for Config
impl Sync for Config
impl Unpin for Config
impl UnwindSafe for Config
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more