Skip to main content

Config

Trait Config 

Source
pub trait Config:
    for<'de> Deserialize<'de>
    + Serialize
    + Debug {
    // Provided method
    fn validate(&self) -> Result<(), FoundationError> { ... }
}
Expand description

When enabled, primitive fields like boolean, string, integer, etc. will be generated as macro calls such as primitive_boolean!("active", true) instead of regular struct fields. These macros automatically generate both the primitive field and its companion extension field. Configuration trait that all configuration types should implement.

This trait provides a common interface for configuration objects, ensuring they can be serialized/deserialized and validated.

§Example

use rh_foundation::Config;
use serde::{Deserialize, Serialize};

#[derive(Debug, Serialize, Deserialize)]
struct MyConfig {
    name: String,
    port: u16,
}

impl Config for MyConfig {
    fn validate(&self) -> rh_foundation::Result<()> {
        if self.port == 0 {
            return Err(rh_foundation::FoundationError::InvalidInput(
                "Port cannot be 0".to_string()
            ));
        }
        Ok(())
    }
}

Provided Methods§

Source

fn validate(&self) -> Result<(), FoundationError>

Validate the configuration.

Returns Ok(()) if the configuration is valid, or an error describing what is invalid.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§