Skip to content

Commit

Permalink
fixup clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
werkshy committed Apr 16, 2024
1 parent c31be30 commit d018b60
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 21 deletions.
4 changes: 2 additions & 2 deletions rs/src/api/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub async fn add(data: web::Data<AppState>, input: web::Json<ApiQueueInput>) ->
};

let maybe_tracks = data.collection.get_tracks_under(&collection_location);
if (maybe_tracks.is_none()) {
if maybe_tracks.is_none() {
return HttpResponse::NotFound().body("Not found");
}
let tracks = maybe_tracks.unwrap();
Expand All @@ -63,7 +63,7 @@ pub async fn add(data: web::Data<AppState>, input: web::Json<ApiQueueInput>) ->
if input.clear {
queue.clear();
}
queue.add_tracks(tracks.into_iter().map(|track| track.clone()).collect());
queue.add_tracks(tracks.into_iter().cloned().collect());
HttpResponse::Ok().body("ok")
}

Expand Down
27 changes: 14 additions & 13 deletions rs/src/filemanager/collection.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
use std::{
collections::{BTreeMap, VecDeque},
path::PathBuf,
collections::{BTreeMap},
};

use lazy_static::lazy_static;
use regex::Regex;



use super::{
cache,
collection_builder::{build, CollectionBuilder},
collection_builder::{build},
dto::CollectionLocation,
model::{Category, Track},
options::CollectionOptions,
utils::generate_id,
};

const DEFAULT_CATEGORY: &str = "Music";
Expand All @@ -29,6 +27,12 @@ pub fn init(options: CollectionOptions) -> std::io::Result<Collection> {
Ok(collection)
}

impl Default for Collection {
fn default() -> Self {
Self::new()
}
}

impl Collection {
pub fn new() -> Self {
Self {
Expand Down Expand Up @@ -69,9 +73,7 @@ impl Collection {
*/
pub fn get_tracks_under(&self, location: &CollectionLocation) -> Option<Vec<&Track>> {
let maybe_category = self.categories.get(&location.category);
if maybe_category.is_none() {
return None;
}
maybe_category?;
let category = maybe_category.unwrap();

let maybe_tracks = match (&location.artist, &location.album, &location.disc) {
Expand Down Expand Up @@ -105,8 +107,7 @@ impl Collection {
return maybe_tracks.and_then(|tracks| {
tracks
.iter()
.find(|track| track.name == *location.track.as_ref().unwrap())
.and_then(|track| Some(vec![track.clone()]))
.find(|track| track.name == *location.track.as_ref().unwrap()).map(|track| vec![track.clone()])
});
}
}
Expand All @@ -115,9 +116,9 @@ impl Collection {
mod tests {
use super::*;
use crate::filemanager::model::factories::*;
use crate::filemanager::model::Track;

use factori::create;
use std::path::PathBuf;


#[test]
fn test_add_category() {
Expand Down
3 changes: 1 addition & 2 deletions rs/src/filemanager/collection_builder.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
use std::{
borrow::Cow,
collections::{BTreeMap, VecDeque},
collections::{VecDeque},
path::PathBuf,
};

use lazy_static::lazy_static;
use regex::Regex;

use super::{
cache,
collection::Collection,
model::{Category, Track},
utils::generate_id,
Expand Down
2 changes: 1 addition & 1 deletion rs/src/filemanager/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ fn list_album(album: &Album, indent: usize) {
let space = " ".repeat(indent);
log::info!("{space}[al]{}", album.name);

for (disc_name, disc) in &album.discs {
for (_disc_name, disc) in &album.discs {
list_album(disc, indent + 2);
}

Expand Down
6 changes: 3 additions & 3 deletions rs/src/filemanager/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,11 @@ pub mod factories {
});

pub fn random_string() -> String {
let id = thread_rng()

thread_rng()
.sample_iter(&Alphanumeric)
.take(30)
.map(char::from)
.collect();
id
.collect()
}
}

0 comments on commit d018b60

Please sign in to comment.