Repository: starship/starship
File: src/config.rs (Rust)

Code before:
                key,
                value,
                value.type_str()
            );
        }
        array_value
    }

    /// Get a text key and attempt to interpret it into an ANSI style.
    fn get_as_ansi_style(&self, key: &str) -> Option<ansi_term::Style> {
        let style_string = self.get_as_str(key)?;
        parse_style_string(style_string)
    }

    /// Get a key from a module's configuration as a segment config.
    ///
    /// The config can be
    ///
    /// - a string, will be interpreted as value.
    /// - a table with optional { value, style } keys.
    ///   If omitted, default value will be used.
    ///
    /// Returns `Some(SegmentConfig)` if key exists in the configuration, else `None`.
    fn get_as_segment_config(&self, key: &str) -> Option<SegmentConfig> {
        let segment_config = self.get_config(key)?;
        match segment_config {
            toml::Value::String(value) => Some(SegmentConfig {
                value: Some(value.as_str()),
                style: None,
            }),
            toml::Value::Table(config_table) => Some(SegmentConfig {
                value: config_table.get_as_str("value"),
                style: config_table.get_as_ansi_style("style"),
            }),
            _ => {
                log::debug!(
                    "Expected \"{}\" to be a string or config table. Instead received {} of type {}.",
                    key,
                    segment_config,
                    segment_config.type_str()
                );
                None
            }
        }
    }
}

/** Parse a style string which represents an ansi style. Valid tokens in the style
 string include the following:
 - 'fg:<color>'    (specifies that the color read should be a foreground color)
 - 'bg:<color>'    (specifies that the color read should be a background color)

Review comment (suggestion):
how about
```
self.get_config(key).map(|segmentconfig| {
  match segment_config ...
})
```

Code after:
                }),
                toml::Value::Table(config_table) => Some(SegmentConfig {
                    value: config_table.get_as_str("value"),
                    style: config_table.get_as_ansi_style("style"),
                }),
                _ => {
                    log::debug!(
                        "Expected \"{}\" to be a string or config table. Instead received {} of type {}.",
                        key,
                        segment_config,
                        segment_config.type_str()
                        );
                    None
                }
            }
        })
    }
}

fn log_if_key_found(key: &str, something: Option<&Value>) {
    if something.is_some() {
        log::trace!("Value found for \"{}\": {:?}", key, &something);
    } else {
        log::trace!("No value found for \"{}\"", key);
    }
}

fn log_if_type_correct<T: std::fmt::Debug>(
    key: &str,
    something: &Value,
    casted_something: Option<T>,
) {
    if let Some(casted) = casted_something {
        log::trace!(
            "Value under key \"{}\" has the expected type. Proceeding with {:?} which was build from {:?}.",
            key,
            casted,
            something
            );
    } else {
        log::debug!(
            "Value under key \"{}\" did not have the expected type. Instead received {} of type {}.",
            key,
            something,
            something.type_str()
            );
    }
}

/** Parse a style string which represents an ansi style. Valid tokens in the style
 string include the following: