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

Code before:
    }

    /// Check if `disabled` option of the module is true in configuration file.
    pub fn is_module_disabled_in_config(&self, name: &str) -> bool {
        let config = self.config.get_module_config(name);

        // If the segment has "disabled" set to "true", don't show it
        let disabled = config.and_then(|table| table.as_table()?.get("disabled")?.as_bool());

        disabled == Some(true)
    }

    /// Returns true when no negated environment variable is defined in `env_vars`
    /// or none of the negated variables is set in the environment.
    fn has_no_negative_env_var(&self, env_vars: &'a [&'a str]) -> bool {
        !env_vars
            .iter()
            .any(|env_var| env_var.starts_with('!') && self.get_env(&env_var[1..]).is_some())
    }

    /// Returns true if 'detect_env_vars' is empty,
    /// or if at least one environment variable is set and no negated environment variable is set
    pub fn detect_env_vars(&'a self, env_vars: &'a [&'a str]) -> bool {
        env_vars.is_empty()
            || ((env_vars.iter().any(|e| self.get_env(e).is_some()))
                && self.has_no_negative_env_var(env_vars))
    }

    // returns a new ScanDir struct with reference to current dir_files of context
    // see ScanDir for methods
    pub fn try_begin_scan(&'a self) -> Option<ScanDir<'a>> {
        Some(ScanDir {
            dir_contents: self.dir_contents().ok()?,
            files: &[],
            folders: &[],
            extensions: &[],
        })
    }

    /// Begins an ancestor scan at the current directory, see [`ScanAncestors`] for available
    /// methods.
    pub fn begin_ancestor_scan(&'a self) -> ScanAncestors<'a> {
        ScanAncestors {
            path: &self.current_dir,
            files: &[],
            folders: &[],
        }
    }

    /// Will lazily get repo root and branch when a module requests it.
    pub fn get_repo(&self) -> Result<&Repo, Box<gix::discover::Error>> {

Review comment (suggestion):
Instead of `env_vars.is_empty()` it might be better to use `env_vars.any(|e| !e.starts_with('!'))` to better support negative-only matchers.

Code after:
    }

    /// Check if `disabled` option of the module is true in configuration file.
    pub fn is_module_disabled_in_config(&self, name: &str) -> bool {
        let config = self.config.get_module_config(name);

        // If the segment has "disabled" set to "true", don't show it
        let disabled = config.and_then(|table| table.as_table()?.get("disabled")?.as_bool());

        disabled == Some(true)
    }

    /// Returns true when a negated environment variable is defined in `env_vars` and is present
    fn has_negated_env_var(&self, env_vars: &'a [&'a str]) -> bool {
        env_vars
            .iter()
            .filter_map(|env_var| env_var.strip_prefix('!'))
            .any(|env_var| self.get_env(env_var).is_some())
    }

    /// Returns true if 'detect_env_vars' is empty,
    /// or if at least one environment variable is set and no negated environment variable is set
    pub fn detect_env_vars(&'a self, env_vars: &'a [&'a str]) -> bool {
        if env_vars.is_empty() {
            return true;
        }

        if self.has_negated_env_var(env_vars) {
            return false;
        }

        // Returns true if at least one environment variable is set
        let mut iter = env_vars
            .iter()
            .filter(|env_var| !env_var.starts_with('!'))
            .peekable();

        iter.peek().is_none() || iter.any(|env_var| self.get_env(env_var).is_some())
    }

    // returns a new ScanDir struct with reference to current dir_files of context
    // see ScanDir for methods
    pub fn try_begin_scan(&'a self) -> Option<ScanDir<'a>> {
        Some(ScanDir {
            dir_contents: self.dir_contents().ok()?,
            files: &[],
            folders: &[],
            extensions: &[],
        })
    }