Skip to main content

ConfigItem

Trait ConfigItem 

Source
pub trait ConfigItem:
    DeserializeOwned
    + Clone
    + Send
    + Sync
    + 'static {
    // Required method
    fn toml_key() -> &'static str;

    // Provided method
    fn register(state: &State, config: &Config) { ... }
}
Expand description

Trait for configuration section types.

Types implementing this trait can be used with Config::get() to extract and deserialize specific sections from the configuration table.

Use the #[config(key = "section_name")] macro to automatically implement this trait. The macro will also auto-register the config type using the inventory crate.

use sword::prelude::*;

#[config(key = "my_section")]
struct MyConfig {
    value: String,
}

Required Methods§

Source

fn toml_key() -> &'static str

Returns the TOML section key for this configuration type.

Provided Methods§

Source

fn register(state: &State, config: &Config)

Registers this config type in the application State. This is called automatically during application bootstrap.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§