feat(rust): Configure when the module is shown (#2350)

This makes it possible to configure when the rust module is shown
based on the contents of a directory.
This commit is contained in:
David Knaack
2021-02-21 18:01:17 +01:00
committed by GitHub
parent 9ba82e8d92
commit a499f30157
3 changed files with 22 additions and 15 deletions
+6
View File
@@ -8,6 +8,9 @@ pub struct RustConfig<'a> {
pub symbol: &'a str,
pub style: &'a str,
pub disabled: bool,
pub detect_extensions: Vec<&'a str>,
pub detect_files: Vec<&'a str>,
pub detect_folders: Vec<&'a str>,
}
impl<'a> RootModuleConfig<'a> for RustConfig<'a> {
@@ -17,6 +20,9 @@ impl<'a> RootModuleConfig<'a> for RustConfig<'a> {
symbol: "🦀 ",
style: "bold red",
disabled: false,
detect_extensions: vec!["rs"],
detect_files: vec!["Cargo.toml"],
detect_folders: vec![],
}
}
}
+6 -8
View File
@@ -10,23 +10,21 @@ use crate::configs::rust::RustConfig;
use crate::formatter::StringFormatter;
/// Creates a module with the current Rust version
///
/// Will display the Rust version if any of the following criteria are met:
/// - Current directory contains a file with a `.rs` extension
/// - Current directory contains a `Cargo.toml` file
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
let mut module = context.new_module("rust");
let config = RustConfig::try_load(module.config);
let is_rs_project = context
.try_begin_scan()?
.set_files(&["Cargo.toml"])
.set_extensions(&["rs"])
.set_files(&config.detect_files)
.set_extensions(&config.detect_extensions)
.set_folders(&config.detect_folders)
.is_match();
if !is_rs_project {
return None;
}
let mut module = context.new_module("rust");
let config = RustConfig::try_load(module.config);
let parsed = StringFormatter::new(config.format).and_then(|formatter| {
formatter
.map_meta(|var, _| match var {