pub trait Config:
for<'de> Deserialize<'de>
+ Serialize
+ Debug {
// Provided method
fn validate(&self) -> Result<()> { ... }
}Expand description
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§
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.