Repository: sharkdp/bat
File: src/controller.rs (Rust)

Code before:
    pub fn run_with_error_handler(&self, handle_error: impl Fn(&Error)) -> Result<bool> {
        // Do not launch the pager if NONE of the input files exist
        let mut paging_mode = self.config.paging_mode;
        if self.config.paging_mode != PagingMode::Never {
            let call_pager = self.config.files.iter().any(|file| {
                if let InputFile::Ordinary(path) = file {
                    return Path::new(path).exists();
                } else {
                    return true;
                }
            });
            if !call_pager {
                paging_mode = PagingMode::Never;
            }
        }

        let mut output_type = OutputType::from_mode(paging_mode, self.config.pager)?;
        let writer = output_type.handle()?;
        let mut no_errors: bool = true;

        let stdin = io::stdin();

        let filenames = if self.config.filenames.is_none() {
            vec![None; self.config.files.len()]
        } else {
            self.config
                .filenames
                .as_ref()
                .unwrap()
                .into_iter()
                .map(|name| Some(*name))
                .collect()
        };

        for it in self.config.files.iter().zip(filenames) {
            let (input_file, file_name) = it;
            match input_file.get_reader(&stdin) {
                Err(error) => {
                    handle_error(&error);
                    no_errors = false;
                }
                Ok(mut reader) => {
                    let result = if self.config.loop_through {
                        let mut printer = SimplePrinter::new();
                        self.print_file(reader, &mut printer, writer, *input_file, file_name)
                    } else {
                        let mut printer = InteractivePrinter::new(
                            &self.config,
                            &self.assets,
                            *input_file,
                            &mut reader,

Review comment (suggestion):
Similar here. Using a `match` statement would be more idiomatic and shorter (in general, we try to avoid `.unwrap` calls):
``` rust
let filenames = match self.config.filenames {
    Some(ref filenames) => filenames.into_iter().map(|name| Some(*name)).collect(),
    None => vec![None; self.config.files.len()],
};
```
Seeing that this vector is only being built up to be iterated over directly afterwards, we can also skip the `.collect()` part and just use the iterator directly:
``` rust
let filenames: Box<dyn Iterator<Item = _>> = match self.config.filenames {
    Some(ref filenames) => Box::new(filenames.into_iter().map(|name| Some(*name))),
    None => Box::new(std::iter::repeat(None)),
};
```

Code after:
    pub fn run_with_error_handler(&self, handle_error: impl Fn(&Error)) -> Result<bool> {
        // Do not launch the pager if NONE of the input files exist
        let mut paging_mode = self.config.paging_mode;
        if self.config.paging_mode != PagingMode::Never {
            let call_pager = self.config.files.iter().any(|file| {
                if let InputFile::Ordinary(path) = file {
                    return Path::new(path).exists();
                } else {
                    return true;
                }
            });
            if !call_pager {
                paging_mode = PagingMode::Never;
            }
        }

        let mut output_type = OutputType::from_mode(paging_mode, self.config.pager)?;
        let writer = output_type.handle()?;
        let mut no_errors: bool = true;

        let stdin = io::stdin();

        let filenames: Box<dyn Iterator<Item = _>> = match self.config.filenames {
            Some(ref filenames) => Box::new(filenames.into_iter().map(|name| Some(*name))),
            None => Box::new(std::iter::repeat(None)),
        };

        for (input_file, file_name) in self.config.files.iter().zip(filenames) {
            match input_file.get_reader(&stdin) {
                Err(error) => {
                    handle_error(&error);
                    no_errors = false;
                }
                Ok(mut reader) => {
                    let result = if self.config.loop_through {
                        let mut printer = SimplePrinter::new();
                        self.print_file(reader, &mut printer, writer, *input_file, file_name)
                    } else {
                        let mut printer = InteractivePrinter::new(
                            &self.config,
                            &self.assets,
                            *input_file,
                            &mut reader,
                        );
                        self.print_file(reader, &mut printer, writer, *input_file, file_name)
                    };

                    if let Err(error) = result {
                        handle_error(&error);
                        no_errors = false;
                    }