Repository: starship/starship
File: src/modules/directory.rs (Rust)

Code before:
        } else {
            String::from(config.truncation_symbol)
        }
    } else {
        String::from("")
    };

    let mut path_vec = match &repo.and_then(|r| r.workdir.as_ref()) {
        Some(repo_root) if config.repo_root_style.is_some() => {
            let contracted_path = contract_repo_path(display_dir, repo_root)?;
            let repo_path_vec: Vec<&str> = contracted_path.split('/').collect();
            let after_repo_root = contracted_path.replacen(repo_path_vec[0], "", 1);
            let num_segments_after_root = after_repo_root.split('/').count();

            if ((num_segments_after_root - 1) as i64) < config.truncation_length {
                let root = repo_path_vec[0];
                let before = dir_string.replace(&contracted_path, "");
                [prefix + &before, root.to_string(), after_repo_root]
            } else {
                ["".to_string(), "".to_string(), prefix + &dir_string]
            }
        }
        _ => ["".to_string(), "".to_string(), prefix + &dir_string],
    };

    if config.convert_slash {
        path_vec.iter_mut().for_each(|i| *i = from_slash(i));
    }

    let lock_symbol = String::from(config.read_only);
    let display_format = if path_vec[0].is_empty() && path_vec[1].is_empty() {
        config.format
    } else {
        config.repo_root_format
    };
    let repo_root_style = config.repo_root_style.unwrap_or(config.style);

    let parsed = StringFormatter::new(display_format).and_then(|formatter| {
        formatter
            .map_style(|variable| match variable {
                "style" => Some(Ok(config.style)),
                "read_only_style" => Some(Ok(config.read_only_style)),
                "repo_root_style" => Some(Ok(repo_root_style)),
                _ => None,
            })
            .map(|variable| match variable {
                "path" => Some(Ok(&path_vec[2])),
                "before_root_path" => Some(Ok(&path_vec[0])),
                "repo_root" => Some(Ok(&path_vec[1])),
                "read_only" => {
                    if is_readonly_dir(physical_dir) {

Review comment (suggestion):
We don't actually need to make `path_vec` mutable for this right? We can shadow the old variable, e.g.

```suggestion
    let path_vec = if config.convert_slash { path_vec.iter().for_each(|i| *i = from_slash(i)).collect() } else { path_vec };
```

though this also might just be my dislike for mutable state getting the better of me.

Code after:
        } else {
            String::from(config.truncation_symbol)
        }
    } else {
        String::from("")
    };

    let path_vec = match &repo.and_then(|r| r.workdir.as_ref()) {
        Some(repo_root) if config.repo_root_style.is_some() => {
            let contracted_path = contract_repo_path(display_dir, repo_root)?;
            let repo_path_vec: Vec<&str> = contracted_path.split('/').collect();
            let after_repo_root = contracted_path.replacen(repo_path_vec[0], "", 1);
            let num_segments_after_root = after_repo_root.split('/').count();

            if ((num_segments_after_root - 1) as i64) < config.truncation_length {
                let root = repo_path_vec[0];
                let before = dir_string.replace(&contracted_path, "");
                [prefix + &before, root.to_string(), after_repo_root]
            } else {
                ["".to_string(), "".to_string(), prefix + &dir_string]
            }
        }
        _ => ["".to_string(), "".to_string(), prefix + &dir_string],
    };

    let path_vec = if config.use_os_path_sep {
        path_vec.map(|i| convert_path_sep(&i))
    } else {
        path_vec
    };

    let lock_symbol = String::from(config.read_only);
    let display_format = if path_vec[0].is_empty() && path_vec[1].is_empty() {
        config.format
    } else {
        config.repo_root_format
    };
    let repo_root_style = config.repo_root_style.unwrap_or(config.style);

    let parsed = StringFormatter::new(display_format).and_then(|formatter| {
        formatter
            .map_style(|variable| match variable {
                "style" => Some(Ok(config.style)),
                "read_only_style" => Some(Ok(config.read_only_style)),
                "repo_root_style" => Some(Ok(repo_root_style)),
                _ => None,
            })
            .map(|variable| match variable {
                "path" => Some(Ok(&path_vec[2])),
                "before_root_path" => Some(Ok(&path_vec[0])),
                "repo_root" => Some(Ok(&path_vec[1])),