Clippy pedantic fixes

This commit is contained in:
2024-09-22 02:16:18 +03:00
parent 387a5eaf4a
commit f7008e882c
22 changed files with 162 additions and 275 deletions

View File

@@ -2,6 +2,7 @@
pub mod song;
pub mod playlist;
use playlist::Playlist;
use song::Song;
use std::{collections::HashMap, fmt::{Debug, Display}, path::PathBuf};
@@ -10,7 +11,7 @@ use anyhow::{bail, Result};
use serde::{Deserialize, Serialize};
const DEFAULT_MANIFEST: &'static str = include_str!("../../manifest.default.json");
const DEFAULT_MANIFEST: &str = include_str!("../../manifest.default.json");
@@ -51,7 +52,7 @@ impl Manifest {
self.get_playlist_mut(playlist_name)?.get_song_mut(name)
}
pub fn add_playlist(&mut self, playlist_name: String) {
self.playlists.insert(playlist_name, Default::default());
self.playlists.insert(playlist_name, Playlist::default());
}
pub fn get_playlist(&self, playlist_name: &String) -> Option<&playlist::Playlist> {
self.playlists.get(playlist_name)
@@ -67,7 +68,7 @@ impl Manifest {
}
pub fn get_song_count(&self) -> usize {
let mut count = 0;
for (_, v) in &self.playlists {
for v in self.playlists.values() {
count += v.len();
}
count
@@ -98,7 +99,7 @@ impl Manifest {
let mut s = Self::default();
log::debug!("Path: {p:?}");
s.path = p.clone();
s.path.clone_from(p);
s.load(Some(p))?;
Ok(s)
}

View File

@@ -1,9 +1,9 @@
use std::str::FromStr;
use std::{fmt::Display, str::FromStr};
use anyhow::{bail, Result};
use serde::{Deserialize, Serialize};
#[allow(clippy::pedantic)]
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, Default)]
pub enum SongType {
#[default]
@@ -12,14 +12,14 @@ pub enum SongType {
Soundcloud,
}
impl ToString for SongType {
fn to_string(&self) -> String {
let s = match self {
SongType::Youtube => "Youtube",
SongType::Spotify => "Spotify",
SongType::Soundcloud => "Soundcloud",
};
String::from(s)
impl Display for SongType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Soundcloud => write!(f, "SoundCloud")?,
Self::Spotify => write!(f, "Spotify")?,
Self::Youtube => write!(f, "YouTube")?,
}
Ok(())
}
}
@@ -31,8 +31,9 @@ pub struct Song {
#[allow(dead_code)]
impl Song {
pub fn from_url_str(url: String) -> Result<Self> {
Self::from_url(url::Url::from_str(url.as_str())?)
#[allow(clippy::needless_pass_by_value)]
pub fn from_url_str<S: ToString>(url: S) -> Result<Self> {
Self::from_url(url::Url::from_str(&url.to_string())?)
}
pub fn from_url(url: url::Url) -> Result<Self> {
Ok(Self {