pub fn module<'a>(name: &str, context: &'a Context) -> Option<Module<'a>> {
    let start: Instant = Instant::now();
    let toml_config = context.config.get_custom_module_config(name).expect(
        "modules::custom::module should only be called after ensuring that the module exists",
    );
    let config = CustomConfig::load(toml_config);

    let mut scan_dir = context.try_begin_scan()?;

    if !config.files.0.is_empty() {
        scan_dir = scan_dir.set_files(&config.files.0);
    }
    if !config.extensions.0.is_empty() {
        scan_dir = scan_dir.set_extensions(&config.extensions.0);
    }
    if !config.directories.0.is_empty() {
        scan_dir = scan_dir.set_folders(&config.directories.0);
    }

    let mut is_match = scan_dir.is_match();

    if !is_match {
        if let Some(when) = config.when {
            is_match = exec_when(when, &config.shell.0);
        }

        if !is_match {
            return None;
        }
    }

    let mut module = Module::new(name, config.description, Some(toml_config));

    let output = exec_command(config.command, &config.shell.0)?;

    let trimmed = output.trim();
    if !trimmed.is_empty() {
        let parsed = StringFormatter::new(config.format).and_then(|formatter| {
            formatter
                .map_meta(|var, _| match var {
                    "symbol" => Some(config.symbol),
                    _ => None,
                })
                .map_style(|variable| match variable {
                    "style" => Some(Ok(config.style)),
                    _ => None,
                })
                .map(|variable| match variable {
                    // This may result in multiple calls to `get_module_version` when a user have
                    // multiple `$version` variables defined in `format`.
                    "output" => Some(Ok(trimmed)),
                    _ => None,
                })
                .parse(None)
        });

        match parsed {
            Ok(segments) => module.set_segments(segments),
            Err(error) => {
                log::warn!("Error in module `custom.{}`:\n{}", name, error);
            }
        };
    }
    let elapsed = start.elapsed();
    log::trace!("Took {:?} to compute custom module {:?}", elapsed, name);
    module.duration = elapsed;
    Some(module)
}
/// Creates a custom module with some configuration
///
/// The relevant TOML config will set the files, extensions, and directories needed
/// for the module to be displayed. If none of them match, and optional "when"
/// command can be run -- if its result is 0, the module will be shown.
///
/// Finally, the content of the module itself is also set by a command.
Creates a custom module with some configuration
The relevant TOML config will set the files, extensions, and directories needed
for the module to be displayed. If none of them match, and optional "when"
command can be run -- if its result is 0, the module will be shown.

Finally, the content of the module itself is also set by a command.
Creates a custom module with some configuration The relevant TOML config will set the files extensions and directories needed for the module to be displayed . If none of them match and optional " when " command can be run -- if its result is 0 the module will be shown . Finally the content of the module itself is also set by a command .
pub fn module<'a>(name: &str, context: &'a Context) -> Option<Module<'a>> {
    let start: Instant = Instant::now();
    let toml_config = context.config.get_custom_module_config(name).expect(
        "modules::custom::module should only be called after ensuring that the module exists",
    );
    let config = CustomConfig::load(toml_config);
    let mut scan_dir = context.try_begin_scan()?;
    if !config.files.0.is_empty() {
        scan_dir = scan_dir.set_files(&config.files.0);
    }
    if !config.extensions.0.is_empty() {
        scan_dir = scan_dir.set_extensions(&config.extensions.0);
    }
    if !config.directories.0.is_empty() {
        scan_dir = scan_dir.set_folders(&config.directories.0);
    }
    let mut is_match = scan_dir.is_match();
    if !is_match {
        if let Some(when) = config.when {
            is_match = exec_when(when, &config.shell.0);
        }
        if !is_match {
            return None;
        }
    }
    let mut module = Module::new(name, config.description, Some(toml_config));
    let output = exec_command(config.command, &config.shell.0)?;
    let trimmed = output.trim();
    if !trimmed.is_empty() {
        let parsed = StringFormatter::new(config.format).and_then(|formatter| {
            formatter
                .map_meta(|var, _| match var {
                    "symbol" => Some(config.symbol),
                    _ => None,
                })
                .map_style(|variable| match variable {
                    "style" => Some(Ok(config.style)),
                    _ => None,
                })
                .map(|variable| match variable {
                    // This may result in multiple calls to `get_module_version` when a user have
                    // multiple `$version` variables defined in `format`.
                    "output" => Some(Ok(trimmed)),
                    _ => None,
                })
                .parse(None)
        });
        match parsed {
            Ok(segments) => module.set_segments(segments),
            Err(error) => {
                log::warn!("Error in module `custom.{}`:\n{}", name, error);
            }
        };
    }
    let elapsed = start.elapsed();
    log::trace!("Took {:?} to compute custom module {:?}", elapsed, name);
    module.duration = elapsed;
    Some(module)
}
pub fn module < ' a > ( name : & str , context : & ' a Context ) -> Option < Module < ' a > > { let start : Instant = Instant :: now ( ) ; let toml_config = context . config . get_custom_module_config ( name ) . expect ( " " , ) ; let config = CustomConfig :: load ( toml_config ) ; let mut scan_dir = context . try_begin_scan ( ) ? ; if ! config . files . 0 . is_empty ( ) { scan_dir = scan_dir . set_files ( & config . files . 0 ) ; } if ! config . extensions . 0 . is_empty ( ) { scan_dir = scan_dir . set_extensions ( & config . extensions . 0 ) ; } if ! config . directories . 0 . is_empty ( ) { scan_dir = scan_dir . set_folders ( & config . directories . 0 ) ; } let mut is_match = scan_dir . is_match ( ) ; if ! is_match { if let Some ( when ) = config . when { is_match = exec_when ( when , & config . shell . 0 ) ; } if ! is_match { return None ; } } let mut module = Module :: new ( name , config . description , Some ( toml_config ) ) ; let output = exec_command ( config . command , & config . shell . 0 ) ? ; let trimmed = output . trim ( ) ; if ! trimmed . is_empty ( ) { let parsed = StringFormatter :: new ( config . format ) . and_then ( | formatter | { formatter . map_meta ( | var , _ | match var { " " => Some ( config . symbol ) , _ => None , } ) . map_style ( | variable | match variable { " " => Some ( Ok ( config . style ) ) , _ => None , } ) . map ( | variable | match variable { // This may result in multiple calls to `get_module_version` when a user have // multiple `$version` variables defined in `format`. " " => Some ( Ok ( trimmed ) ) , _ => None , } ) . parse ( None ) } ) ; match parsed { Ok ( segments ) => module . set_segments ( segments ) , Err ( error ) => { log :: warn ! ( " \n " name error ) ; } } ; } let elapsed = start . elapsed ( ) ; log :: trace ! ( " " elapsed name ) ; module . duration = elapsed ; Some ( module ) }
Creates a custom module with some configuration
The relevant TOML config will set the files, extensions, and directories needed
for the module to be displayed.
Creates a custom module with some configuration The relevant TOML config will set the files extensions and directories needed for the module to be displayed .
name
&str
context
&'a Context