Expand description
§Product OS Configuration
A helper crate that provides traits, utilities, and conventions for structuring configuration across the Product OS suite of crates.
§What This Crate Provides
ProductOSConfigtrait: A standard interface that all Product OS configuration types should implement, supporting file loading, unified config files, and validation.- File loading utilities: Generic JSON config file loading via
loadermodule. - Serde conventions: The
product_os_config!macro enforces consistent serialization. - Shared types: Cross-cutting types like
LogLevelandConfigError. - Validation framework: A
ConfigErrortype for structured validation errors.
§Features
std- Enable standard library supportconfig_file- Enable loading configuration from JSON files (requiresstd)full- Enable all features
§no_std Support
This crate supports no_std environments with alloc. By default, no features
are enabled for minimal dependencies.
§Examples
§Defining a configuration type
use product_os_configuration::{product_os_config, ProductOSConfig, ConfigError};
product_os_config! {
pub struct MyServiceConfig {
pub port: u16,
pub host: String,
}
}
impl Default for MyServiceConfig {
fn default() -> Self {
Self {
port: 8080,
host: String::from("localhost"),
}
}
}
impl ProductOSConfig for MyServiceConfig {
const SECTION_KEY: &'static str = "myService";
fn validate(&self) -> Result<(), ConfigError> {
if self.port == 0 {
return Err(ConfigError::ValidationError(vec!["port must be non-zero".into()]));
}
Ok(())
}
}Re-exports§
pub use error::ConfigError;pub use logging::LogLevel;pub use logging::Logging;
Modules§
- error
- Configuration error types
- loader
- Configuration file loading utilities (requires
config_filefeature). - logging
- Logging configuration structures
Macros§
- product_
os_ config - Macro to apply standard Product OS serde configuration to a struct or enum.
Traits§
- ProductOS
Config - Trait that all Product OS configuration types should implement.