refactor(singularity): use ? operator (#2518)

This commit is contained in:
Dario Vladović 2021-03-27 18:53:54 +01:00 committed by GitHub
parent cf68f54611
commit 1336944ab7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -7,8 +7,7 @@ use crate::formatter::StringFormatter;
/// ///
/// Will display the Singularity image if `$SINGULARITY_NAME` is set. /// Will display the Singularity image if `$SINGULARITY_NAME` is set.
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> { pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
let singularity_env = context.get_env("SINGULARITY_NAME"); let singularity_env = context.get_env("SINGULARITY_NAME")?;
singularity_env.as_ref()?;
let mut module = context.new_module("singularity"); let mut module = context.new_module("singularity");
let config: SingularityConfig = SingularityConfig::try_load(module.config); let config: SingularityConfig = SingularityConfig::try_load(module.config);
@ -24,7 +23,7 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
_ => None, _ => None,
}) })
.map(|variable| match variable { .map(|variable| match variable {
"env" => singularity_env.as_ref().map(Ok), "env" => Some(Ok(&singularity_env)),
_ => None, _ => None,
}) })
.parse(None) .parse(None)