From e976509dae0f3d3f81e17b626fa5eb3b9552b013 Mon Sep 17 00:00:00 2001 From: Thomas Frans Date: Thu, 4 Apr 2024 20:46:08 +0200 Subject: [PATCH] chore: remove todo and improve some code in `src/library.rs` --- src/library.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/library.rs b/src/library.rs index 5e3be13..7d988d7 100644 --- a/src/library.rs +++ b/src/library.rs @@ -401,13 +401,14 @@ impl Library { } } - // TODO: Add documentation - fn insert_artist(&self, id: &str, name: &str) { + /// Add the artist with `id` and `name` to the user library, but don't sync with the API. + /// This does not add if there is already an artist with `id`. + fn insert_artist(&self, id: String, name: String) { let mut artists = self.artists.write().unwrap(); if !artists .iter() - .any(|a| a.id.clone().unwrap_or_default() == id) + .any(|a| a.id.as_ref().is_some_and(|value| *value == id)) { let mut artist = Artist::new(id.to_string(), name.to_string()); artist.tracks = Some(Vec::new()); @@ -522,7 +523,7 @@ impl Library { track_artists.dedup_by(|a, b| a.0 == b.0); for (id, name) in track_artists.iter() { - self.insert_artist(id, name); + self.insert_artist(id.to_string(), name.to_string()); } }