diff --git a/src/api/albums.rs b/src/api/albums.rs index d74f193..8828941 100644 --- a/src/api/albums.rs +++ b/src/api/albums.rs @@ -29,7 +29,7 @@ pub async fn add_album(album_title: String, release_date: Option, image_ let parsed_release_date = match release_date { Some(date) => { - match NaiveDate::parse_from_str(&date.trim(), "%Y-%m-%d") { + match NaiveDate::parse_from_str(date.trim(), "%Y-%m-%d") { Ok(parsed_date) => Some(parsed_date), Err(_e) => return Err(ServerFnError::::ServerError("Invalid release date".to_string())) } @@ -37,16 +37,7 @@ pub async fn add_album(album_title: String, release_date: Option, image_ None => None }; - let image_path_arg = match image_path { - Some(image_path) => { - if image_path.is_empty() { - None - } else { - Some(image_path) - } - }, - None => None - }; + let image_path_arg = image_path.filter(|image_path| !image_path.is_empty()); let new_album = Album { id: None, diff --git a/src/api/artists.rs b/src/api/artists.rs index 35c705c..75a7fe4 100644 --- a/src/api/artists.rs +++ b/src/api/artists.rs @@ -92,7 +92,7 @@ pub async fn top_songs_by_artist(artist_id: i32, limit: Option) -> Result = song_play_counts.into_iter().collect(); - let top_song_ids: Vec = song_play_counts.iter().map(|(song_id, _)| *song_id).collect(); + let top_song_ids: Vec = song_play_counts.keys().copied().collect(); let top_songs: Vec<(Song, Option, Option, Option<(i32, i32)>, Option<(i32, i32)>)> = songs::table @@ -131,20 +131,20 @@ pub async fn top_songs_by_artist(artist_id: i32, limit: Option) -> Result) -> Result = top_songs_map.into_iter().map(|(_, v)| v).collect(); + let mut top_songs: Vec<(frontend::Song, i64)> = top_songs_map.into_values().collect(); top_songs.sort_by(|(_, plays1), (_, plays2)| plays2.cmp(plays1)); Ok(top_songs) } @@ -205,7 +205,7 @@ pub async fn albums_by_artist(artist_id: i32, limit: Option) -> Result = albums_map.into_iter().map(|(_, v)| v).collect(); + let mut albums: Vec = albums_map.into_values().collect(); albums.sort_by(|a1, a2| a2.release_date.cmp(&a1.release_date)); Ok(albums) } diff --git a/src/api/auth.rs b/src/api/auth.rs index 7d6bff6..2a8f017 100644 --- a/src/api/auth.rs +++ b/src/api/auth.rs @@ -114,9 +114,9 @@ pub async fn check_auth() -> Result { /// use libretunes::api::auth::require_auth; /// #[server(endpoint = "protected_route")] /// pub async fn protected_route() -> Result<(), ServerFnError> { -/// require_auth().await?; -/// // Continue with protected route -/// Ok(()) +/// require_auth().await?; +/// // Continue with protected route +/// Ok(()) /// } /// ``` #[cfg(feature = "ssr")] @@ -125,7 +125,7 @@ pub async fn require_auth() -> Result<(), ServerFnError> { if logged_in { Ok(()) } else { - Err(ServerFnError::::ServerError(format!("Unauthorized"))) + Err(ServerFnError::::ServerError("Unauthorized".to_string())) } }) } @@ -139,10 +139,10 @@ pub async fn require_auth() -> Result<(), ServerFnError> { /// use libretunes::api::auth::get_user; /// #[server(endpoint = "user_route")] /// pub async fn user_route() -> Result<(), ServerFnError> { -/// let user = get_user().await?; -/// println!("Logged in as: {}", user.username); -/// // Do something with the user -/// Ok(()) +/// let user = get_user().await?; +/// println!("Logged in as: {}", user.username); +/// // Do something with the user +/// Ok(()) /// } /// ``` #[cfg(feature = "ssr")] @@ -184,9 +184,9 @@ pub async fn check_admin() -> Result { /// use libretunes::api::auth::require_admin; /// #[server(endpoint = "protected_admin_route")] /// pub async fn protected_admin_route() -> Result<(), ServerFnError> { -/// require_admin().await?; -/// // Continue with protected route -/// Ok(()) +/// require_admin().await?; +/// // Continue with protected route +/// Ok(()) /// } /// ``` #[cfg(feature = "ssr")] @@ -195,7 +195,7 @@ pub async fn require_admin() -> Result<(), ServerFnError> { if is_admin { Ok(()) } else { - Err(ServerFnError::::ServerError(format!("Unauthorized"))) + Err(ServerFnError::::ServerError("Unauthorized".to_string())) } }) } diff --git a/src/api/profile.rs b/src/api/profile.rs index 6d3b2e2..96a38f7 100644 --- a/src/api/profile.rs +++ b/src/api/profile.rs @@ -126,20 +126,20 @@ pub async fn recent_songs(for_user_id: i32, limit: Option) -> Result = history_counts.into_iter().collect(); - let history_song_ids = history_counts.iter().map(|(song_id, _)| *song_id).collect::>(); + let history_song_ids = history_counts.keys().copied().collect::>(); // Get the song data for the songs listened to in the date range let history_songs: Vec<(Song, Option, Option, Option<(i32, i32)>, Option<(i32, i32)>)> @@ -227,20 +227,20 @@ pub async fn top_songs(for_user_id: i32, start_date: NaiveDateTime, end_date: Na }; let image_path = song.image_path.unwrap_or( - album.as_ref().map(|album| album.image_path.clone()).flatten() + album.as_ref().and_then(|album| album.image_path.clone()) .unwrap_or("/assets/images/placeholders/MusicPlaceholder.svg".to_string())); let songdata = frontend::Song { id: song_id, title: song.title, artists: artist.map(|artist| vec![artist]).unwrap_or_default(), - album: album, + album, track: song.track, duration: song.duration, release_date: song.release_date, song_path: song.storage_path, - image_path: image_path, - like_dislike: like_dislike, + image_path, + like_dislike, added_date: song.added_date.unwrap(), }; diff --git a/src/api/songs.rs b/src/api/songs.rs index b508606..b8b669d 100644 --- a/src/api/songs.rs +++ b/src/api/songs.rs @@ -84,8 +84,7 @@ pub async fn get_song_by_id(song_id: i32) -> Result, Serv .load(db_con)?; let song = song_parts.first().cloned(); - let artists = song_parts.into_iter().map(|(_, _, artist, _, _)| artist) - .filter_map(|artist| artist).collect::>(); + let artists = song_parts.into_iter().filter_map(|(_, _, artist, _, _)| artist).collect::>(); match song { Some((song, album, _artist, like, dislike)) => { @@ -99,13 +98,13 @@ pub async fn get_song_by_id(song_id: i32) -> Result, Serv Ok(Some(frontend::Song { id: song.id.unwrap(), title: song.title.clone(), - artists: artists, - album: album.clone().map(|album| album.into()), + artists, + album: album.clone(), track: song.track, duration: song.duration, release_date: song.release_date, song_path: song.storage_path.clone(), - image_path: image_path, + image_path, like_dislike: Some((like.is_some(), dislike.is_some())), added_date: song.added_date.unwrap(), })) diff --git a/src/api/upload.rs b/src/api/upload.rs index 75f91a3..1be3e9f 100644 --- a/src/api/upload.rs +++ b/src/api/upload.rs @@ -108,13 +108,13 @@ async fn validate_track_number(track_number: Field<'static>) -> Result() { if track_number < 0 { - return Err(ServerFnError:::: - ServerError("Track number must be positive or 0".to_string())); + Err(ServerFnError:::: + ServerError("Track number must be positive or 0".to_string())) } else { Ok(Some(track_number)) } } else { - return Err(ServerFnError::::ServerError("Error parsing track number".to_string())); + Err(ServerFnError::::ServerError("Error parsing track number".to_string())) } }, Err(e) => Err(ServerFnError::::ServerError(format!("Error reading track number: {}", e)))?, @@ -131,7 +131,7 @@ async fn validate_release_date(release_date: Field<'static>) -> Result Ok(Some(release_date)), @@ -192,10 +192,11 @@ pub async fn upload(data: MultipartData) -> Result<(), ServerFnError> { .read(true) .write(true) .create(true) + .truncate(true) .open(upload_path.clone())?; while let Some(chunk) = field.chunk().await? { - file.write(&chunk)?; + file.write_all(&chunk)?; } file.flush()?; diff --git a/src/components/add_album.rs b/src/components/add_album.rs index eee0de7..7f8adbe 100644 --- a/src/components/add_album.rs +++ b/src/components/add_album.rs @@ -42,7 +42,7 @@ pub fn AddAlbum(open: RwSignal) -> impl IntoView { release_date.set("".to_string()); image_path.set("".to_string()); } - }) + }); }; view! { diff --git a/src/components/add_artist.rs b/src/components/add_artist.rs index 9ff27ad..51df834 100644 --- a/src/components/add_artist.rs +++ b/src/components/add_artist.rs @@ -34,7 +34,7 @@ pub fn AddArtist(open: RwSignal) -> impl IntoView { log!("Added artist: {:?}", artist); artist_name.set("".to_string()); } - }) + }); }; view! { diff --git a/src/components/personal.rs b/src/components/personal.rs index fb5e015..46cb431 100644 --- a/src/components/personal.rs +++ b/src/components/personal.rs @@ -26,9 +26,7 @@ pub fn Profile() -> impl IntoView { let user_profile_picture = move || { user.get().and_then(|user| { if let Some(user) = user { - if user.id.is_none() { - return None; - } + user.id?; Some(format!("/assets/images/profile/{}.webp", user.id.unwrap())) } else { None diff --git a/src/components/playbar.rs b/src/components/playbar.rs index 212b3ef..fbf121b 100644 --- a/src/components/playbar.rs +++ b/src/components/playbar.rs @@ -96,13 +96,11 @@ pub fn set_playing(play: bool) { status.playing = true; log!("Successfully played audio"); } + } else if let Err(e) = audio.pause() { + error!("Unable to pause audio: {:?}", e); } else { - if let Err(e) = audio.pause() { - error!("Unable to pause audio: {:?}", e); - } else { - status.playing = false; - log!("Successfully paused audio"); - } + status.playing = false; + log!("Successfully paused audio"); } } else { error!("Unable to play/pause audio: Audio element not available"); @@ -239,7 +237,7 @@ fn MediaInfo() -> impl IntoView { let artist = Signal::derive(move || { status.with(|status| { - status.queue.front().map_or("".into(), |song| format!("{}", Artist::display_list(&song.artists))) + status.queue.front().map_or("".into(), |song| Artist::display_list(&song.artists).to_string()) }) }); @@ -324,7 +322,6 @@ fn LikeDislike() -> impl IntoView { }, _ => { log!("Unable to like song: No song in queue"); - return; } } }); @@ -364,7 +361,6 @@ fn LikeDislike() -> impl IntoView { }, _ => { log!("Unable to dislike song: No song in queue"); - return; } } }); @@ -532,13 +528,13 @@ pub fn PlayBar() -> impl IntoView { if let Some(src) = src { GlobalState::play_status().with_untracked(|status| { if let Some(audio) = status.get_audio() { - audio.set_src(&src); + audio.set_src(src); } else { error!("Unable to set audio source: Audio element not available"); } }); } - }) + }); }); // Track the last song that was added to the history to prevent duplicates diff --git a/src/components/song_list.rs b/src/components/song_list.rs index efa0301..9a73aa3 100644 --- a/src/components/song_list.rs +++ b/src/components/song_list.rs @@ -158,7 +158,15 @@ pub fn SongArtists(artists: Vec) -> impl IntoView { Either::Right(view! { {artist.name.clone()} }) } } - {if i < num_artists - 2 { ", " } else if i == num_artists - 2 { " & " } else { "" }} + { + use std::cmp::Ordering; + + match i.cmp(&(num_artists - 2)) { + Ordering::Less => ", ", + Ordering::Equal => " & ", + Ordering::Greater => "", + } + } } }).collect::>() } @@ -224,13 +232,10 @@ pub fn SongLikeDislike( // If an error occurs, check the like/dislike status again to ensure consistency let check_like_dislike = move || { spawn_local(async move { - match get_like_dislike_song(song_id.get_untracked()).await { - Ok((like, dislike)) => { - liked.set(like); - disliked.set(dislike); - }, - Err(_) => {} - } + if let Ok((like, dislike)) = get_like_dislike_song(song_id.get_untracked()).await { + liked.set(like); + disliked.set(dislike); + } }); }; diff --git a/src/components/upload.rs b/src/components/upload.rs index 3034ef0..89582bf 100644 --- a/src/components/upload.rs +++ b/src/components/upload.rs @@ -60,7 +60,7 @@ pub fn Upload(open: RwSignal) -> impl IntoView { set_filtered_artists.update(|value| *value = artists); } - }) + }); }; // Create a filter function to handle filtering albums // Allow users to search for albums by title, converts the album title to album id to be handed off to backend @@ -80,7 +80,7 @@ pub fn Upload(open: RwSignal) -> impl IntoView { log!("Filtered albums: {:?}", albums); set_filtered_albums.update(|value| *value = albums); } - }) + }); }; let handle_response = Arc::new(move |response: &Response| { @@ -116,12 +116,12 @@ pub fn Upload(open: RwSignal) -> impl IntoView { Artists 0} + when=move || {!filtered_artists.get().is_empty()} fallback=move || view! {} >
    { - move || filtered_artists.get().iter().enumerate().map(|(_index,filtered_artist)| view! { + move || filtered_artists.get().iter().map(|filtered_artist| view! { }).collect::>() } @@ -134,12 +134,12 @@ pub fn Upload(open: RwSignal) -> impl IntoView { Album ID 0} + when=move || {!filtered_albums.get().is_empty()} fallback=move || view! {} >
      { - move || filtered_albums.get().iter().enumerate().map(|(_index,filtered_album)| view! { + move || filtered_albums.get().iter().map(|filtered_album| view! { }).collect::>() } @@ -190,12 +190,12 @@ pub fn Artist(artist: Artist, artists: ReadSignal, set_artists: WriteSig let mut ids: Vec<&str> = all_artirts.split(",").collect(); //If there is only one artist in the input, get their id equivalent and add it to the string if ids.len() == 1 { - let value_str = match artist.id.clone() { + let value_str = match artist.id { Some(v) => v.to_string(), None => String::from("None"), }; s.push_str(&value_str); - s.push_str(","); + s.push(','); set_artists.update(|value| *value = s); //If there are multiple artists in the input, pop the last artist by string off the vector, //get their id equivalent, and add it to the string @@ -203,14 +203,14 @@ pub fn Artist(artist: Artist, artists: ReadSignal, set_artists: WriteSig ids.pop(); for id in ids { s.push_str(id); - s.push_str(","); + s.push(','); } - let value_str = match artist.id.clone() { + let value_str = match artist.id { Some(v) => v.to_string(), None => String::from("None"), }; s.push_str(&value_str); - s.push_str(","); + s.push(','); set_artists.update(|value| *value = s); } //Clear the search results @@ -227,7 +227,7 @@ pub fn Artist(artist: Artist, artists: ReadSignal, set_artists: WriteSig pub fn Album(album: Album, _albums: ReadSignal, set_albums: WriteSignal, set_filtered: WriteSignal>) -> impl IntoView { //Converts album title to album id to upload a song let add_album = move |_| { - let value_str = match album.id.clone() { + let value_str = match album.id { Some(v) => v.to_string(), None => String::from("None"), }; diff --git a/src/error_template.rs b/src/error_template.rs index 328f441..dfadf17 100644 --- a/src/error_template.rs +++ b/src/error_template.rs @@ -12,7 +12,7 @@ pub enum AppError { } impl AppError { - pub fn status_code(&self) -> StatusCode { + pub const fn status_code(&self) -> StatusCode { match self { AppError::NotFound => StatusCode::NOT_FOUND, } diff --git a/src/main.rs b/src/main.rs index 3da726a..7211d8d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -42,7 +42,7 @@ async fn main() { debug!("Connecting to Redis..."); let redis_url = std::env::var("REDIS_URL").expect("REDIS_URL must be set"); - let redis_config = RedisConfig::from_url(&redis_url).expect(&format!("Unable to parse Redis URL: {}", redis_url)); + let redis_config = RedisConfig::from_url(&redis_url).unwrap_or_else(|_| panic!("Unable to parse Redis URL: {}", redis_url)); let redis_pool = RedisPool::new(redis_config, None, None, None, 1).expect("Unable to create Redis pool"); redis_pool.connect(); redis_pool.wait_for_connect().await.expect("Unable to connect to Redis"); @@ -72,7 +72,7 @@ async fn main() { .fallback(file_and_error_handler) .with_state(leptos_options); - let listener = tokio::net::TcpListener::bind(&addr).await.expect(&format!("Could not bind to {}", &addr)); + let listener = tokio::net::TcpListener::bind(&addr).await.unwrap_or_else(|_| panic!("Could not bind to {}", &addr)); info!("Listening on http://{}", &addr); diff --git a/src/models/backend/album.rs b/src/models/backend/album.rs index 79e38e2..34b38a4 100644 --- a/src/models/backend/album.rs +++ b/src/models/backend/album.rs @@ -153,8 +153,8 @@ impl Album { duration: song.duration, release_date: song.release_date, song_path: song.storage_path, - image_path: image_path, - like_dislike: like_dislike, + image_path, + like_dislike, added_date: song.added_date.unwrap(), }; diff --git a/src/models/backend/artist.rs b/src/models/backend/artist.rs index c154da3..e42a0a0 100644 --- a/src/models/backend/artist.rs +++ b/src/models/backend/artist.rs @@ -26,7 +26,7 @@ impl Artist { /// /// For one artist, displays [artist1]. For two artists, displays [artist1] & [artist2]. /// For three or more artists, displays [artist1], [artist2], & [artist3]. - pub fn display_list(artists: &Vec) -> String { + pub fn display_list(artists: &[Artist]) -> String { let mut artist_list = String::new(); for (i, artist) in artists.iter().enumerate() { diff --git a/src/models/backend/user.rs b/src/models/backend/user.rs index 9af3430..a866705 100644 --- a/src/models/backend/user.rs +++ b/src/models/backend/user.rs @@ -14,8 +14,8 @@ cfg_if! { // Model for a "User", used for querying the database /// Various fields are wrapped in Options, because they are not always wanted for inserts/retrieval -/// Using deserialize_as makes Diesel use the specified type when deserializing from the database, -/// and then call .into() to convert it into the Option +/// Using `deserialize_as` makes Diesel use the specified type when deserializing from the database, +/// and then call `.into()` to convert it into the Option #[cfg_attr(feature = "ssr", derive(Queryable, Selectable, Insertable))] #[cfg_attr(feature = "ssr", diesel(table_name = crate::schema::users))] #[cfg_attr(feature = "ssr", diesel(check_for_backend(diesel::pg::Pg)))] @@ -55,10 +55,10 @@ impl User { /// # Returns /// /// * `Result, Box>` - - /// A result indicating success with a vector of history entries, or an error + /// A result indicating success with a vector of history entries, or an error /// #[cfg(feature = "ssr")] - pub fn get_history(self: &Self, limit: Option, conn: &mut PgPooledConn) -> + pub fn get_history(&self, limit: Option, conn: &mut PgPooledConn) -> Result, Box> { use crate::schema::song_history::dsl::*; @@ -94,10 +94,10 @@ impl User { /// # Returns /// /// * `Result, Box>` - - /// A result indicating success with a vector of listen dates and songs, or an error + /// A result indicating success with a vector of listen dates and songs, or an error /// #[cfg(feature = "ssr")] - pub fn get_history_songs(self: &Self, limit: Option, conn: &mut PgPooledConn) -> + pub fn get_history_songs(&self, limit: Option, conn: &mut PgPooledConn) -> Result, Box> { use crate::schema::songs::dsl::*; use crate::schema::song_history::dsl::*; @@ -140,7 +140,7 @@ impl User { /// * `Result<(), Box>` - A result indicating success with an empty value, or an error /// #[cfg(feature = "ssr")] - pub fn add_history(self: &Self, song_id: i32, conn: &mut PgPooledConn) -> Result<(), Box> { + pub fn add_history(&self, song_id: i32, conn: &mut PgPooledConn) -> Result<(), Box> { use crate::schema::song_history; let my_id = self.id.ok_or("Artist id must be present (Some) to add history")?; @@ -155,7 +155,7 @@ impl User { /// Like or unlike a song for this user /// If likeing a song, remove dislike if it exists #[cfg(feature = "ssr")] - pub async fn set_like_song(self: &Self, song_id: i32, like: bool, conn: &mut PgPooledConn) -> + pub async fn set_like_song(&self, song_id: i32, like: bool, conn: &mut PgPooledConn) -> Result<(), Box> { use log::*; debug!("Setting like for song {} to {}", song_id, like); @@ -184,7 +184,7 @@ impl User { /// Get the like status of a song for this user #[cfg(feature = "ssr")] - pub async fn get_like_song(self: &Self, song_id: i32, conn: &mut PgPooledConn) -> Result> { + pub async fn get_like_song(&self, song_id: i32, conn: &mut PgPooledConn) -> Result> { use crate::schema::song_likes; let my_id = self.id.ok_or("User id must be present (Some) to get like status of a song")?; @@ -201,7 +201,7 @@ impl User { /// Dislike or remove dislike from a song for this user /// If disliking a song, remove like if it exists #[cfg(feature = "ssr")] - pub async fn set_dislike_song(self: &Self, song_id: i32, dislike: bool, conn: &mut PgPooledConn) -> + pub async fn set_dislike_song(&self, song_id: i32, dislike: bool, conn: &mut PgPooledConn) -> Result<(), Box> { use log::*; debug!("Setting dislike for song {} to {}", song_id, dislike); @@ -231,7 +231,7 @@ impl User { /// Get the dislike status of a song for this user #[cfg(feature = "ssr")] - pub async fn get_dislike_song(self: &Self, song_id: i32, conn: &mut PgPooledConn) -> Result> { + pub async fn get_dislike_song(&self, song_id: i32, conn: &mut PgPooledConn) -> Result> { use crate::schema::song_dislikes; let my_id = self.id.ok_or("User id must be present (Some) to get dislike status of a song")?; diff --git a/src/models/frontend/album.rs b/src/models/frontend/album.rs index 07fe98c..89c852f 100644 --- a/src/models/frontend/album.rs +++ b/src/models/frontend/album.rs @@ -23,13 +23,13 @@ pub struct Album { pub image_path: String, } -impl Into for Album { - fn into(self) -> DashboardTile { +impl From for DashboardTile { + fn from(val: Album) -> Self { DashboardTile { - image_path: self.image_path.into(), - title: self.title.into(), - link: format!("/album/{}", self.id).into(), - description: Some(format!("Album • {}", Artist::display_list(&self.artists)).into()), + image_path: val.image_path.into(), + title: val.title.into(), + link: format!("/album/{}", val.id).into(), + description: Some(format!("Album • {}", Artist::display_list(&val.artists)).into()), } } } diff --git a/src/models/frontend/artist.rs b/src/models/frontend/artist.rs index 8522efc..028040b 100644 --- a/src/models/frontend/artist.rs +++ b/src/models/frontend/artist.rs @@ -15,12 +15,12 @@ pub struct Artist { pub image_path: String, } -impl Into for Artist { - fn into(self) -> DashboardTile { +impl From for DashboardTile { + fn from(val: Artist) -> Self { DashboardTile { - image_path: self.image_path.into(), - title: self.name.into(), - link: format!("/artist/{}", self.id).into(), + image_path: val.image_path.into(), + title: val.name.into(), + link: format!("/artist/{}", val.id).into(), description: Some("Artist".into()), } } diff --git a/src/models/frontend/playstatus.rs b/src/models/frontend/playstatus.rs index 3a474a4..7d8f860 100644 --- a/src/models/frontend/playstatus.rs +++ b/src/models/frontend/playstatus.rs @@ -5,7 +5,7 @@ use std::collections::VecDeque; use crate::models::frontend; -/// Represents the global state of the audio player feature of LibreTunes +/// Represents the global state of the audio player feature of `LibreTunes` pub struct PlayStatus { /// Whether or not the audio player is currently playing pub playing: bool, @@ -27,9 +27,9 @@ impl PlayStatus { /// use leptos::prelude::*; /// let status = libretunes::models::frontend::PlayStatus::default(); /// if let Some(audio) = status.audio_player { - /// if let Some(audio) = audio.get() { - /// let _ = audio.play(); - /// } + /// if let Some(audio) = audio.get() { + /// let _ = audio.play(); + /// } /// } /// ``` /// @@ -37,7 +37,7 @@ impl PlayStatus { /// ``` /// let status = libretunes::models::frontend::PlayStatus::default(); /// if let Some(audio) = status.get_audio() { - /// let _ = audio.play(); + /// let _ = audio.play(); /// } /// ``` pub fn get_audio(&self) -> Option { @@ -52,7 +52,7 @@ impl PlayStatus { } impl Default for PlayStatus { - /// Creates a paused PlayStatus with no audio player, no progress update handle, and empty queue/history + /// Creates a paused `PlayStatus` with no audio player, no progress update handle, and empty queue/history fn default() -> Self { Self { playing: false, diff --git a/src/models/frontend/song.rs b/src/models/frontend/song.rs index fcdb1e9..d2f2a52 100644 --- a/src/models/frontend/song.rs +++ b/src/models/frontend/song.rs @@ -39,10 +39,10 @@ pub struct Song { impl TryInto for Song { type Error = Box; - /// Convert a SongData object into a Song object + /// Convert a `SongData` object into a Song object /// /// The SongData/Song conversions are also not truly reversible, - /// due to the way the image_path data is handled. + /// due to the way the `image_path` data is handled. fn try_into(self) -> Result { Ok(backend::Song { id: Some(self.id), @@ -67,13 +67,13 @@ impl TryInto for Song { } } -impl Into for Song { - fn into(self) -> DashboardTile { +impl From for DashboardTile { + fn from(val: Song) -> Self { DashboardTile { - image_path: self.image_path.into(), - title: self.title.into(), - link: format!("/song/{}", self.id).into(), - description: Some(format!("Song • {}", Artist::display_list(&self.artists)).into()), + image_path: val.image_path.into(), + title: val.title.into(), + link: format!("/song/{}", val.id).into(), + description: Some(format!("Song • {}", Artist::display_list(&val.artists)).into()), } } } diff --git a/src/pages/albumpage.rs b/src/pages/albumpage.rs index 2430935..252874e 100644 --- a/src/pages/albumpage.rs +++ b/src/pages/albumpage.rs @@ -28,7 +28,7 @@ pub fn AlbumPage() -> impl IntoView { |value| async move { match value { Ok(v) => {get_songs(v).await}, - Err(e) => {Err(ServerFnError::Request(format!("Error getting song data: {}", e).into()))}, + Err(e) => {Err(ServerFnError::Request(format!("Error getting song data: {}", e)))}, } }, ); @@ -38,7 +38,7 @@ pub fn AlbumPage() -> impl IntoView { |value| async move { match value { Ok(v) => {get_album(v).await}, - Err(e) => {Err(ServerFnError::Request(format!("Error getting song data: {}", e).into()))}, + Err(e) => {Err(ServerFnError::Request(format!("Error getting song data: {}", e)))}, } }, ); diff --git a/src/pages/artist.rs b/src/pages/artist.rs index 94b10a8..4522ece 100644 --- a/src/pages/artist.rs +++ b/src/pages/artist.rs @@ -152,9 +152,7 @@ fn AlbumsByArtist(#[prop(into)] artist_id: Signal) -> impl IntoView { let albums = albums_by_artist(artist_id, None).await; albums.map(|albums| { - albums.into_iter().map(|album| { - album - }).collect::>() + albums.into_iter().collect::>() }) }); diff --git a/src/pages/login.rs b/src/pages/login.rs index c524364..f7e0345 100644 --- a/src/pages/login.rs +++ b/src/pages/login.rs @@ -96,7 +96,7 @@ pub fn Login() -> impl IntoView { Password