addressing clippy lints

This commit is contained in:
Aravinth Manivannan 2021-07-05 14:46:56 +05:30
parent 747a474e9e
commit 209682b33c
Signed by: realaravinth
GPG key ID: AD9F0F08E855ED88
3 changed files with 51 additions and 61 deletions

View file

@ -12,9 +12,7 @@
//! use cache_buster::Files; //! use cache_buster::Files;
//! use cache_buster::CACHE_BUSTER_DATA_FILE; //! use cache_buster::CACHE_BUSTER_DATA_FILE;
//! //!
//! fn main(){
//! let files = Files::new(CACHE_BUSTER_DATA_FILE); //! let files = Files::new(CACHE_BUSTER_DATA_FILE);
//! }
//! ``` //! ```
use std::collections::HashMap; use std::collections::HashMap;

View file

@ -27,7 +27,6 @@
//! ```no_run //! ```no_run
//! use cache_buster::BusterBuilder; //! use cache_buster::BusterBuilder;
//! //!
//! fn main() {
//! // note: add error checking yourself. //! // note: add error checking yourself.
//! // println!("cargo:rustc-env=GIT_process={}", git_process); //! // println!("cargo:rustc-env=GIT_process={}", git_process);
//! let types = vec![ //! let types = vec![
@ -47,7 +46,6 @@
//! .unwrap(); //! .unwrap();
//! //!
//! config.process().unwrap(); //! config.process().unwrap();
//! }
//! ``` //! ```
//! - `main.rs`: //! - `main.rs`:
//! //!
@ -59,11 +57,9 @@
//! use cache_buster::Files; //! use cache_buster::Files;
//! use cache_buster::CACHE_BUSTER_DATA_FILE; //! use cache_buster::CACHE_BUSTER_DATA_FILE;
//! //!
//! fn main(){
//! let files = Files::new(CACHE_BUSTER_DATA_FILE); //! let files = Files::new(CACHE_BUSTER_DATA_FILE);
//! // the path to the file before setting up for cache busting //! // the path to the file before setting up for cache busting
//! files.get("./dist/github.svg"); //! files.get("./dist/github.svg");
//! }
//! ``` //! ```
pub mod processor; pub mod processor;

View file

@ -12,7 +12,6 @@
//! ```rust //! ```rust
//! use cache_buster::BusterBuilder; //! use cache_buster::BusterBuilder;
//! //!
//! fn main() {
//! // note: add error checking yourself. //! // note: add error checking yourself.
//! // println!("cargo:rustc-env=GIT_process={}", git_process); //! // println!("cargo:rustc-env=GIT_process={}", git_process);
//! let types = vec![ //! let types = vec![
@ -32,7 +31,6 @@
//! .unwrap(); //! .unwrap();
//! //!
//! config.process().unwrap(); //! config.process().unwrap();
//! }
//! ``` //! ```
//! //!
//! There's a runtime component to this library which will let you read modified //! There's a runtime component to this library which will let you read modified
@ -135,7 +133,7 @@ impl<'a> Buster<'a> {
for mime_type in self.mime_types.iter() { for mime_type in self.mime_types.iter() {
let file_mime = mime_guess::from_path(path) let file_mime = mime_guess::from_path(path)
.first() .first()
.expect(&format!("couldn't resolve MIME for file: {:?}", &path)); .unwrap_or_else(|| panic!("couldn't resolve MIME for file: {:?}", &path));
if &file_mime == mime_type { if &file_mime == mime_type {
let contents = Self::read_to_string(&path).unwrap(); let contents = Self::read_to_string(&path).unwrap();
let hash = Self::hasher(&contents); let hash = Self::hasher(&contents);
@ -177,7 +175,7 @@ impl<'a> Buster<'a> {
if let Some(prefix) = &self.prefix { if let Some(prefix) = &self.prefix {
//panic!("{}", &prefix); //panic!("{}", &prefix);
let mut result = self.result.as_str(); let mut result = self.result.as_str();
if result.chars().nth(0) == Some('/') { if result.starts_with('/') {
result = &self.result[1..]; result = &self.result[1..];
} }
let destination = Path::new(prefix) let destination = Path::new(prefix)
@ -185,10 +183,10 @@ impl<'a> Buster<'a> {
.join(rel_location) .join(rel_location)
.join(name); .join(name);
(source, destination.into()) (source, destination)
} else { } else {
let destination = Path::new(&self.result).join(rel_location).join(name); let destination = Path::new(&self.result).join(rel_location).join(name);
(source, destination.into()) (source, destination)
} }
} }
@ -211,8 +209,7 @@ impl<'a> Buster<'a> {
if entry_path.is_dir() && path != entry_path { if entry_path.is_dir() && path != entry_path {
Self::create_dir_structure(&self, entry_path)?; Self::create_dir_structure(&self, entry_path)?;
} else { } else if entry_path.is_dir() {
if entry_path.is_dir() {
let rel_location = entry_path.strip_prefix(&self.source).unwrap(); let rel_location = entry_path.strip_prefix(&self.source).unwrap();
let destination = Path::new(&self.result).join(rel_location); let destination = Path::new(&self.result).join(rel_location);
if !destination.exists() { if !destination.exists() {
@ -220,7 +217,6 @@ impl<'a> Buster<'a> {
} }
} }
} }
}
Ok(()) Ok(())
} }
} }
@ -245,11 +241,11 @@ impl Files {
/// Create file map: map original path to modified paths /// Create file map: map original path to modified paths
fn add(&mut self, k: String, v: String) -> Result<(), &'static str> { fn add(&mut self, k: String, v: String) -> Result<(), &'static str> {
if self.map.contains_key(&k) { if let std::collections::hash_map::Entry::Vacant(e) = self.map.entry(k) {
Err("key exists") e.insert(v);
} else {
self.map.insert(k, v);
Ok(()) Ok(())
} else {
Err("key exists")
} }
} }