diff options
| author | Jakob L. Kreuze <zerodaysfordays@sdf.org> | 2020-06-20 21:38:27 -0400 |
|---|---|---|
| committer | Jakob L. Kreuze <zerodaysfordays@sdf.org> | 2020-06-20 21:38:27 -0400 |
| commit | a6bceb230159b18f24da579fcb990d5268bde1df (patch) | |
| tree | f6e93380acf7b6196cc867fff9090854feae17cd | |
| parent | 5d44144716342013afe7f493c78984773cb132b5 (diff) | |
Lint code.
| -rw-r--r-- | src/birka-web.rs | 10 | ||||
| -rw-r--r-- | src/database.rs | 16 |
2 files changed, 12 insertions, 14 deletions
diff --git a/src/birka-web.rs b/src/birka-web.rs index 4e518aa..a3bed1d 100644 --- a/src/birka-web.rs +++ b/src/birka-web.rs @@ -198,7 +198,7 @@ fn update_post(conn: SiteState, id: i64, form: Form<UpdateTags>) -> Result<Json< .lock() .map_err(|_| anyhow!("Could not lock database."))? .tb; - tb.tag_file(id, &form.tags.split(",").collect())?; + tb.tag_file(id, &form.tags.split(',').collect::<Vec<_>>()[..])?; Ok(Json(String::from("Updated!"))) } @@ -224,14 +224,14 @@ fn put_post(conn: SiteState, content_type: &ContentType, data: Data) -> Result<J let filename = raw .file_name - .unwrap_or(thread_rng().sample_iter(&Alphanumeric).take(30).collect()); + .unwrap_or_else(|| thread_rng().sample_iter(&Alphanumeric).take(30).collect()); let path = Path::new(&conn.file_dir).join(&filename); let mut f = File::create(&path)?; f.write_all(&raw.raw)?; let tags = if let Some(mut vec) = data.texts.remove("tags") { let text = vec.remove(0).text; - text.split(',').map(|tag| String::from(tag)).collect() + text.split(',').map(String::from).collect() } else { vec![] }; @@ -322,9 +322,9 @@ fn display_post(conn: SiteState, id: i64) -> Result<Template> { let orig_filename = String::from( Path::new(&file.path) .file_name() - .ok_or(anyhow!("Directory indexed and returned by query"))? + .ok_or_else(|| anyhow!("Directory indexed and returned by query"))? .to_str() - .ok_or(anyhow!("Could not parse filename"))?, + .ok_or_else(|| anyhow!("Could not parse filename"))?, ); let is_image = is_image(&file.path); diff --git a/src/database.rs b/src/database.rs index e5ea02f..5591d6a 100644 --- a/src/database.rs +++ b/src/database.rs @@ -49,18 +49,16 @@ pub fn parse_query<T: AsRef<str>>(query_string: T) -> Result<Query> { .as_ref() .split_whitespace() .map(|part| { - if part.starts_with("-") { + if part.starts_with('-') { if part.len() >= 9 && &part[1..10] == "filename:" { Filename(IsNot(String::from(&part[10..]))) } else { Tag(IsNot(String::from(&part[1..]))) } + } else if part.len() >= 9 && &part[..9] == "filename:" { + Filename(Is(String::from(&part[9..]))) } else { - if part.len() >= 9 && &part[..9] == "filename:" { - Filename(Is(String::from(&part[9..]))) - } else { - Tag(Is(String::from(part))) - } + Tag(Is(String::from(part))) } }) .collect()) @@ -151,7 +149,7 @@ impl TagDatabase { } /// Index the file at `path` in the tag database. - pub fn add_file<T, S>(&self, path: T, tags: &Vec<S>) -> Result<File> + pub fn add_file<T, S>(&self, path: T, tags: &[S]) -> Result<File> where T: AsRef<Path>, S: AsRef<str>, @@ -217,7 +215,7 @@ impl TagDatabase { /// /// If any tag lacks a row in the database, it will be created. The contents /// of `tags` should not contain wildcardcard expressions. - pub fn tag_file<T: AsRef<str>>(&self, id: i64, tags: &Vec<T>) -> Result<()> { + pub fn tag_file<T: AsRef<str>>(&self, id: i64, tags: &[T]) -> Result<()> { for tag in tags.iter() { // Ensure that a row for `tag` into the database. if self.tag_id(tag.as_ref()).is_err() { @@ -235,7 +233,7 @@ impl TagDatabase { /// Remove all of `tags` from the file named by `id`. /// /// The contents of `tags` can contain wildcardcard expressions. - pub fn untag_file<T: AsRef<str>>(&self, id: i64, tags: &Vec<T>) -> Result<()> { + pub fn untag_file<T: AsRef<str>>(&self, id: i64, tags: &[T]) -> Result<()> { for tag in tags.iter() { // Silently skip any tags which do not exist in the database. if let Ok(tags) = self.tag_ids(tag.as_ref()) { |