Skip to content

Commit

Permalink
Clippy lints - July 22 2023 (#900)
Browse files Browse the repository at this point in the history
* Clippy lints

* Add PR number
  • Loading branch information
coreyja authored Jul 22, 2023
1 parent 5274826 commit 867fe7d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 26 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
- Icons updated to match `vim-devicons` and correct Material Designs icons
- Github PR [#899](https://github.com/coreyja/devicon-lookup/pull/899)

### Maintenance

- Various Dependencies Updates
- Clippy and rustfmt changes
- Github PR [#900](https://github.com/coreyja/devicon-lookup/pull/900)

## [0.8.1] - 2023-02-02

### Dependencies
Expand Down
16 changes: 6 additions & 10 deletions src/devicon_lookup.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
use phf::phf_map;
use regex::Regex;
use std::ffi::OsStr;
use std::io::{self, Write};
use std::path::Path;

mod map;
pub mod parsers;

pub const DEFAULT_SYMBOL: &'static str = "";
pub const DEFAULT_SYMBOL: &str = "";

pub type ParserResult = Result<String, &'static str>;
pub type Parser = dyn Fn(ParserResult) -> ParserResult;
Expand All @@ -30,7 +28,7 @@ pub struct LineBuilder<'a> {
impl<'a> LineBuilder<'a> {
pub fn new(original: String) -> Self {
Self {
original: original,
original,
filename_parsers: vec![],
}
}
Expand All @@ -55,11 +53,9 @@ impl<'a> Line<'a> {
curr = parser(curr)
}

curr.and_then(|x| {
Ok(ParsedLine {
original: self.original,
filename: x,
})
curr.map(|x| ParsedLine {
original: self.original,
filename: x,
})
}
}
Expand All @@ -74,7 +70,7 @@ impl ParsedLine {
fn symbol(&self) -> &str {
match self.extension() {
Some(extension) => map::find_symbol(extension),
None => &DEFAULT_SYMBOL,
None => DEFAULT_SYMBOL,
}
}

Expand Down
32 changes: 16 additions & 16 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use std::io::{self, BufRead};
mod devicon_lookup;
use devicon_lookup::*;

const VERSION: &'static str = env!("CARGO_PKG_VERSION");
const USAGE: &'static str = include_str!("USAGE.txt");
const VERSION: &str = env!("CARGO_PKG_VERSION");
const USAGE: &str = include_str!("USAGE.txt");

#[derive(Debug, Deserialize)]
struct Args {
Expand All @@ -28,20 +28,20 @@ impl Cli {
fn process_stdin(&self) {
let stdin = io::stdin();

let maybe_regex_closure =
self.args
.flag_regex
.clone()
.and_then(|string_regex| {
Some(regex::Regex::new(&string_regex).unwrap_or_else(|e| {
panic!("The provided regex could not be parsed: {}", e)
}))
})
.and_then(|regex| Some(devicon_lookup::parsers::regex::parser_from_regex(regex)));

let maybe_prefix_closure = self.args.flag_prefix.clone().and_then(|prefix| {
Some(devicon_lookup::parsers::prefix::parser_from_prefix_delimiter(prefix))
});
let maybe_regex_closure = self
.args
.flag_regex
.clone()
.map(|string_regex| {
regex::Regex::new(&string_regex)
.unwrap_or_else(|e| panic!("The provided regex could not be parsed: {}", e))
})
.map(devicon_lookup::parsers::regex::parser_from_regex);

let maybe_prefix_closure =
self.args.flag_prefix.clone().map(|prefix| {
devicon_lookup::parsers::prefix::parser_from_prefix_delimiter(prefix)
});

for line_result in stdin.lock().lines() {
let line: String = line_result.expect("Failed to read line from stdin");
Expand Down

0 comments on commit 867fe7d

Please sign in to comment.