Skip to main content

OptionalSection

Trait OptionalSection 

Source
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§

Source

fn section_name() -> &'static str

The top-level TOML key for this section (e.g. "message_broker").

Provided Methods§

Source

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 (&[]).

Source

fn on_error() -> OnError

What the feature registry should do when validate_enabled returns an error.

Source

fn metadata() -> FeatureMetadata

Static documentation and ownership annotations for this feature.

Source

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(()).

Source

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".

Implementors§