pub trait OptionalSection:
DeserializeOwned
+ Send
+ Sync
+ 'static {
// Required method
fn section_name() -> &'static str;
// Provided methods
fn requires() -> &'static [&'static str] { ... }
fn on_error() -> OnError { ... }
fn metadata() -> FeatureMetadata { ... }
fn validate_enabled(&self) -> Result<(), ConfigError> { ... }
fn load_optional(
loader: &DefaultLoader,
) -> Result<FeatureState<Self>, ConfigError>
where Self: Sized { ... }
}Expand description
Marks a typed struct as an opt-in TOML feature section.
Unlike ConfigSection, which returns T::default() for absent keys,
OptionalSection treats absence as “feature disabled” and returns
FeatureState::Disabled — no defaults, no error.
Required Methods§
Sourcefn section_name() -> &'static str
fn section_name() -> &'static str
The top-level TOML key for this section (e.g. "message_broker").
Provided Methods§
Sourcefn requires() -> &'static [&'static str]
fn requires() -> &'static [&'static str]
Other section keys this feature requires to be enabled before it can run.
Checked by crate::FeatureRegistryOps::validate_dependencies after all
features are loaded. Default: no dependencies (&[]).
Sourcefn on_error() -> OnError
fn on_error() -> OnError
What the feature registry should do when validate_enabled returns an error.
OnError::Fail(default) — propagate the error; startup halts.OnError::Disable— treat the feature as disabled and continue startup.
Sourcefn metadata() -> FeatureMetadata
fn metadata() -> FeatureMetadata
Static documentation and ownership annotations for this feature.
Sourcefn validate_enabled(&self) -> Result<(), ConfigError>
fn validate_enabled(&self) -> Result<(), ConfigError>
Validate cross-field constraints after the section has been deserialised.
Only called when the section key is present in TOML. Default: always Ok(()).
Sourcefn load_optional(
loader: &DefaultLoader,
) -> Result<FeatureState<Self>, ConfigError>where
Self: Sized,
fn load_optional(
loader: &DefaultLoader,
) -> Result<FeatureState<Self>, ConfigError>where
Self: Sized,
Load this section as an optional feature from loader.
Returns FeatureState::Enabled(Self) when the key is present and valid,
FeatureState::Disabled when absent, and Err for I/O, parse, or
validation failures.
Note: on_error and requires are only applied when loading
through crate::FeatureRegistryOps::load. Use that for full startup
coordination with graceful degradation and dependency validation.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".