Skip to main content

Crate product_os_configuration

Crate product_os_configuration 

Source
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

  • ProductOSConfig trait: 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 loader module.
  • Serde conventions: The product_os_config! macro enforces consistent serialization.
  • Shared types: Cross-cutting types like LogLevel and ConfigError.
  • Validation framework: A ConfigError type for structured validation errors.

§Features

  • std - Enable standard library support
  • config_file - Enable loading configuration from JSON files (requires std)
  • 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_file feature).
logging
Logging configuration structures

Macros§

product_os_config
Macro to apply standard Product OS serde configuration to a struct or enum.

Traits§

ProductOSConfig
Trait that all Product OS configuration types should implement.