diff --git a/src/bin/bat/app.rs b/src/bin/bat/app.rs index 670fe56f..fe0ec588 100644 --- a/src/bin/bat/app.rs +++ b/src/bin/bat/app.rs @@ -23,7 +23,6 @@ use bat::{ line_range::{LineRange, LineRanges}, style::{OutputComponent, OutputComponents, OutputWrap}, syntax_mapping::SyntaxMapping, - util::transpose, Config, PagingMode, }; @@ -198,12 +197,11 @@ impl App { .or_else(|| env::var("BAT_THEME").ok()) .unwrap_or_else(|| String::from(BAT_THEME_DEFAULT)), line_ranges: LineRanges::from( - transpose( - self.matches - .values_of("line-range") - .map(|vs| vs.map(LineRange::from).collect()), - )? - .unwrap_or_else(|| vec![]), + self.matches + .values_of("line-range") + .map(|vs| vs.map(LineRange::from).collect()) + .transpose()? + .unwrap_or_else(|| vec![]), ), output_components, syntax_mapping, @@ -247,13 +245,15 @@ impl App { } else if matches.is_present("plain") { [OutputComponent::Plain].iter().cloned().collect() } else { - let env_style_components: Option> = - transpose(env::var("BAT_STYLE").ok().map(|style_str| { + let env_style_components: Option> = env::var("BAT_STYLE") + .ok() + .map(|style_str| { style_str .split(',') .map(|x| OutputComponent::from_str(&x)) .collect::>>() - }))?; + }) + .transpose()?; matches .value_of("style") diff --git a/src/bin/bat/config.rs b/src/bin/bat/config.rs index cf0714d7..95f76559 100644 --- a/src/bin/bat/config.rs +++ b/src/bin/bat/config.rs @@ -5,7 +5,7 @@ use std::path::PathBuf; use shell_words; -use bat::{dirs::PROJECT_DIRS, util::transpose}; +use bat::dirs::PROJECT_DIRS; pub fn config_file() -> PathBuf { env::var("BAT_CONFIG_PATH") @@ -16,12 +16,11 @@ pub fn config_file() -> PathBuf { } pub fn get_args_from_config_file() -> Result, shell_words::ParseError> { - Ok(transpose( - fs::read_to_string(config_file()) - .ok() - .map(|content| get_args_from_str(&content)), - )? - .unwrap_or_else(|| vec![])) + Ok(fs::read_to_string(config_file()) + .ok() + .map(|content| get_args_from_str(&content)) + .transpose()? + .unwrap_or_else(|| vec![])) } pub fn get_args_from_env_var() -> Option, shell_words::ParseError>> { diff --git a/src/lib.rs b/src/lib.rs index aeeab580..2f057244 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -31,7 +31,6 @@ pub mod printer; pub mod style; pub mod syntax_mapping; pub mod terminal; -pub mod util; pub mod errors { error_chain! { diff --git a/src/util.rs b/src/util.rs deleted file mode 100644 index 4675adbc..00000000 --- a/src/util.rs +++ /dev/null @@ -1,27 +0,0 @@ -/// Helper function that might appear in Rust stable at some point -/// (https://doc.rust-lang.org/stable/std/option/enum.Option.html#method.transpose) -pub fn transpose(opt: Option>) -> Result, E> { - opt.map_or(Ok(None), |res| res.map(Some)) -} - -#[cfg(test)] -mod tests { - use super::transpose; - - #[derive(Debug, PartialEq)] - struct TestError; - - type TestResult = Result; - - #[test] - fn basic() { - let a: Option> = Some(Ok(2)); - assert_eq!(Ok(Some(2)), transpose(a)); - - let b: Option> = Some(Err(TestError)); - assert_eq!(Err(TestError), transpose(b)); - - let c: Option> = None; - assert_eq!(Ok(None), transpose(c)); - } -}