INNER CODE UNIT · Rust

get_string

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

    pub fn get_string(&self, key: &str) -> String {
        self.typed_get(key, String::new(), Setting::to_string)
    }

    /// Reads a map setting, returning an empty vector on unknown key or storage error.
    #[must_use]
    pub fn get_map(&self, key: &str) -> Vec<String> {
        self.typed_get(key, Vec::new(), Setting::to_map)
    }

    /// Shared helper for the typed getters: reads the setting, applies `convert`, or returns
    /// `default` when the key is unknown (logging on a storage error).
    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}");

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…