From e992af1ff3ae60f8797cb96296901249816b071f Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Mon, 15 Feb 2021 14:48:12 -0800 Subject: partial clippy lint cleanup --- fatcat-cli/src/commands.rs | 13 ++++++------- fatcat-cli/src/download.rs | 12 ++++++------ fatcat-cli/src/lib.rs | 2 +- fatcat-cli/src/main.rs | 16 ++++++++-------- fatcat-cli/src/specifier.rs | 2 +- 5 files changed, 22 insertions(+), 23 deletions(-) diff --git a/fatcat-cli/src/commands.rs b/fatcat-cli/src/commands.rs index 4633af6..eb7d5a8 100644 --- a/fatcat-cli/src/commands.rs +++ b/fatcat-cli/src/commands.rs @@ -3,7 +3,6 @@ use chrono_humanize::HumanTime; use fatcat_openapi::models; #[allow(unused_imports)] use log::{self, debug, info}; -use std::convert::TryInto; use std::fs::File; use std::io::{self, BufRead, Write}; use std::path::PathBuf; @@ -269,7 +268,7 @@ pub fn print_entity_histories( history .editgroup .editor - .map_or("-".to_string(), |v| v.username.to_string()), + .map_or("-".to_string(), |v| v.username), history .editgroup .description @@ -446,7 +445,7 @@ impl BatchGrouper { BatchOp::Update => self.push_update( api_client, &json_str, - mutations.clone().unwrap_or(vec![]), + mutations.clone().unwrap_or_default(), )?, BatchOp::Delete => self.push_delete(api_client, &json_str)?, }; @@ -468,7 +467,7 @@ impl BatchGrouper { BatchOp::Update => self.push_update( api_client, &json_str, - mutations.clone().unwrap_or(vec![]), + mutations.clone().unwrap_or_default(), )?, BatchOp::Delete => self.push_delete(api_client, &json_str)?, }; @@ -502,7 +501,7 @@ impl BatchGrouper { let obj: serde_json::Value = serde_json::from_str(json_str)?; let ident = obj["ident"] .as_str() - .ok_or(anyhow!("expect entity JSON to have 'ident' field"))?; + .ok_or_else(|| anyhow!("expect entity JSON to have 'ident' field"))?; let editgroup_id = self.increment_editgroup(api_client)?; let mut entity = entity_model_from_json_str(self.entity_type, &json_str)?; entity.mutate(mutations)?; @@ -521,7 +520,7 @@ impl BatchGrouper { let obj: serde_json::Value = serde_json::from_str(json_str)?; let ident = obj["ident"] .as_str() - .ok_or(anyhow!("expect entity JSON to have 'ident' field"))?; + .ok_or_else(|| anyhow!("expect entity JSON to have 'ident' field"))?; let editgroup_id = self.increment_editgroup(api_client)?; api_client.delete_entity( Specifier::from_ident(self.entity_type, ident.to_string()), @@ -530,7 +529,7 @@ impl BatchGrouper { } pub fn increment_editgroup(&mut self, api_client: &mut FatcatApiClient) -> Result { - if self.current_count >= self.batch_size.try_into().unwrap() { + if self.current_count >= self.batch_size { self.flush(api_client)?; }; self.current_count += 1; diff --git a/fatcat-cli/src/download.rs b/fatcat-cli/src/download.rs index 2fdfeb9..a0f0eeb 100644 --- a/fatcat-cli/src/download.rs +++ b/fatcat-cli/src/download.rs @@ -98,7 +98,7 @@ fn rewrite_wayback_url(url: Url) -> Result { } fn default_filename(specifier: &Specifier, fe: &FileEntity) -> Result { - let file_suffix = match fe.mimetype.as_ref().map(String::as_str) { + let file_suffix = match fe.mimetype.as_deref() { Some("application/pdf") => ".pdf", Some("application/postscript") => ".ps", Some("text/html") => ".html", @@ -131,7 +131,7 @@ pub fn download_file( let final_path = match output_path { Some(ref path) if path.is_dir() => { - let mut full = output_path.unwrap_or(PathBuf::new()); + let mut full = output_path.unwrap_or_default(); full.push(default_filename(specifier, fe)?); full } @@ -151,7 +151,7 @@ pub fn download_file( // TODO: only archive.org URLs (?) let raw_url = match fe.urls.as_ref() { None => return Ok(DownloadStatus::NoPublicFile), - Some(url_list) if url_list.len() == 0 => return Ok(DownloadStatus::NoPublicFile), + Some(url_list) if url_list.is_empty() => return Ok(DownloadStatus::NoPublicFile), // TODO: remove clone (?) // TODO: better heuristic than "just try first URL" Some(url_list) => url_list[0].url.clone(), @@ -288,7 +288,7 @@ fn download_entity( "release_{}\t{}\t{}", re.ident.unwrap(), status, - status.details().unwrap_or("".to_string()) + status.details().unwrap_or_else(|| "".to_string()) ); return Ok((status, status_line)); }; @@ -304,9 +304,9 @@ fn download_entity( "file_{}\t{}\t{}", fe.ident.unwrap(), status, - status.details().unwrap_or("".to_string()) + status.details().unwrap_or_else(|| "".to_string()) ); - return Ok((status, status_line)); + Ok((status, status_line)) } else { Err(anyhow!("not a file entity (JSON)")) } diff --git a/fatcat-cli/src/lib.rs b/fatcat-cli/src/lib.rs index 81dbb7d..d83ee76 100644 --- a/fatcat-cli/src/lib.rs +++ b/fatcat-cli/src/lib.rs @@ -100,7 +100,7 @@ pub fn parse_macaroon_editor_id(s: &str) -> Result { Some(id) => id, None => return Err(anyhow!("expected an editor_id caveat in macaroon token")), }; - verifier.satisfy_exact(&format!("editor_id = {}", editor_id.to_string())); + verifier.satisfy_exact(&format!("editor_id = {}", editor_id)); Ok(editor_id) } diff --git a/fatcat-cli/src/main.rs b/fatcat-cli/src/main.rs index f5f5d8b..15301b5 100644 --- a/fatcat-cli/src/main.rs +++ b/fatcat-cli/src/main.rs @@ -402,7 +402,7 @@ fn run(opt: Opt) -> Result<()> { let ee = api_client.create_entity_from_json( entity_type, &json_str, - editgroup_id.as_string(), + editgroup_id.into_string(), )?; writeln!( &mut std::io::stdout(), @@ -433,7 +433,7 @@ fn run(opt: Opt) -> Result<()> { let ee = api_client.update_entity_from_json( exact_specifier, &json_str, - editgroup_id.as_string(), + editgroup_id.into_string(), )?; writeln!( &mut std::io::stdout(), @@ -451,7 +451,7 @@ fn run(opt: Opt) -> Result<()> { let ee = edit_entity_locally( &mut api_client, specifier, - editgroup_id.as_string(), + editgroup_id.into_string(), json, editing_command, )?; @@ -472,7 +472,7 @@ fn run(opt: Opt) -> Result<()> { } other => { return Err(anyhow!("{:?}", other)) - .with_context(|| format!("failed to fetch changelogs")) + .with_context(|| "failed to fetch changelogs".to_string()) } } } @@ -669,7 +669,7 @@ fn run(opt: Opt) -> Result<()> { editgroup_id, } => { let result = api_client - .delete_entity(specifier.clone(), editgroup_id.as_string()) + .delete_entity(specifier.clone(), editgroup_id.into_string()) .with_context(|| format!("delete entity: {:?}", specifier))?; println!("{}", serde_json::to_string(&result)?); } @@ -749,7 +749,7 @@ fn run(opt: Opt) -> Result<()> { Command::Editgroups { cmd: EditgroupsCommand::Accept { editgroup_id }, } => { - let msg = api_client.accept_editgroup(editgroup_id.as_string())?; + let msg = api_client.accept_editgroup(editgroup_id.into_string())?; writeln!( &mut std::io::stdout(), "{}", @@ -759,7 +759,7 @@ fn run(opt: Opt) -> Result<()> { Command::Editgroups { cmd: EditgroupsCommand::Submit { editgroup_id }, } => { - let msg = api_client.update_editgroup_submit(editgroup_id.as_string(), true)?; + let msg = api_client.update_editgroup_submit(editgroup_id.into_string(), true)?; writeln!( &mut std::io::stdout(), "{}", @@ -769,7 +769,7 @@ fn run(opt: Opt) -> Result<()> { Command::Editgroups { cmd: EditgroupsCommand::Unsubmit { editgroup_id }, } => { - let msg = api_client.update_editgroup_submit(editgroup_id.as_string(), false)?; + let msg = api_client.update_editgroup_submit(editgroup_id.into_string(), false)?; writeln!( &mut std::io::stdout(), "{}", diff --git a/fatcat-cli/src/specifier.rs b/fatcat-cli/src/specifier.rs index ab1a421..c69abf8 100644 --- a/fatcat-cli/src/specifier.rs +++ b/fatcat-cli/src/specifier.rs @@ -617,7 +617,7 @@ impl FromStr for Specifier { pub struct EditgroupSpecifier(String); impl EditgroupSpecifier { - pub fn as_string(self) -> String { + pub fn into_string(self) -> String { self.0 } } -- cgit v1.2.3