INNER CODE UNIT · Rust

typed_get

gosub-io/gosub-engine · crates/gosub_config/src/lib.rs:253

    fn typed_get<T>(&self, key: &str, default: T, convert: impl Fn(&Setting) -> T) -> T {
        match self.get(key) {
            Ok(Some(setting)) => convert(&setting),
            Ok(None) => default,
            Err(err) => {
                warn!("config error: {err}");
                default
            }
        }
    }
}

/// Grants access to a [`Config`] handle. Subsystems that only need to read or watch settings
/// should bound on `T: HasConfig` rather than taking a concrete context type, so they stay
/// decoupled from how the engine is assembled.
pub trait HasConfig {
    /// Returns the configuration handle.
    fn config(&self) -> &Config;

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…