Skip to content

Commit

Permalink
style(clippy): enforce clippy use_self lint
Browse files Browse the repository at this point in the history
Clippy's `use_self` line ensures that `Self` is used instead of the real
name whenever possible. This makes searching easier and cleans up the
code a bit.
  • Loading branch information
ThomasFrans committed Sep 27, 2023
1 parent 01e01b5 commit 3e15f2b
Show file tree
Hide file tree
Showing 25 changed files with 170 additions and 172 deletions.
178 changes: 89 additions & 89 deletions src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub enum MoveAmount {

impl Default for MoveAmount {
fn default() -> Self {
MoveAmount::Integer(1)
Self::Integer(1)
}
}

Expand Down Expand Up @@ -92,8 +92,8 @@ pub enum SeekDirection {
impl fmt::Display for SeekDirection {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let repr = match self {
SeekDirection::Absolute(pos) => format!("{pos}"),
SeekDirection::Relative(delta) => {
Self::Absolute(pos) => format!("{pos}"),
Self::Relative(delta) => {
format!("{}{}", if delta > &0 { "+" } else { "" }, delta)
}
};
Expand All @@ -112,8 +112,8 @@ impl fmt::Display for InsertSource {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let repr = match self {
#[cfg(feature = "share_clipboard")]
InsertSource::Clipboard => "".into(),
InsertSource::Input(url) => url.to_string(),
Self::Clipboard => "".into(),
Self::Input(url) => url.to_string(),
};
write!(f, "{repr}")
}
Expand Down Expand Up @@ -169,23 +169,23 @@ impl fmt::Display for Command {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let mut repr_tokens = vec![self.basename().to_owned()];
let mut extras_args = match self {
Command::Focus(tab) => vec![tab.to_owned()],
Command::Seek(direction) => vec![direction.to_string()],
Command::VolumeUp(amount) => vec![amount.to_string()],
Command::VolumeDown(amount) => vec![amount.to_string()],
Command::Repeat(mode) => match mode {
Self::Focus(tab) => vec![tab.to_owned()],
Self::Seek(direction) => vec![direction.to_string()],
Self::VolumeUp(amount) => vec![amount.to_string()],
Self::VolumeDown(amount) => vec![amount.to_string()],
Self::Repeat(mode) => match mode {
Some(mode) => vec![mode.to_string()],
None => vec![],
},
Command::Shuffle(on) => match on {
Self::Shuffle(on) => match on {
Some(b) => vec![(if *b { "on" } else { "off" }).into()],
None => vec![],
},
#[cfg(feature = "share_clipboard")]
Command::Share(mode) => vec![mode.to_string()],
Command::Open(mode) => vec![mode.to_string()],
Command::Goto(mode) => vec![mode.to_string()],
Command::Move(mode, amount) => match (mode, amount) {
Self::Share(mode) => vec![mode.to_string()],
Self::Open(mode) => vec![mode.to_string()],
Self::Goto(mode) => vec![mode.to_string()],
Self::Move(mode, amount) => match (mode, amount) {
(MoveMode::Playing, _) => vec!["playing".to_string()],
(MoveMode::Up, MoveAmount::Extreme) => vec!["top".to_string()],
(MoveMode::Down, MoveAmount::Extreme) => vec!["bottom".to_string()],
Expand All @@ -194,40 +194,40 @@ impl fmt::Display for Command {
(mode, MoveAmount::Float(amount)) => vec![mode.to_string(), amount.to_string()],
(mode, MoveAmount::Integer(amount)) => vec![mode.to_string(), amount.to_string()],
},
Command::Shift(mode, amount) => vec![mode.to_string(), amount.unwrap_or(1).to_string()],
Command::Search(term) => vec![term.to_owned()],
Command::Jump(mode) => match mode {
Self::Shift(mode, amount) => vec![mode.to_string(), amount.unwrap_or(1).to_string()],
Self::Search(term) => vec![term.to_owned()],
Self::Jump(mode) => match mode {
JumpMode::Previous | JumpMode::Next => vec![],
JumpMode::Query(term) => vec![term.to_owned()],
},
Command::Insert(source) => vec![source.to_string()],
Command::NewPlaylist(name) => vec![name.to_owned()],
Command::Sort(key, direction) => vec![key.to_string(), direction.to_string()],
Command::ShowRecommendations(mode) => vec![mode.to_string()],
Command::Execute(cmd) => vec![cmd.to_owned()],
Command::Quit
| Command::TogglePlay
| Command::Stop
| Command::Previous
| Command::Next
| Command::Clear
| Command::Queue
| Command::PlayNext
| Command::Play
| Command::UpdateLibrary
| Command::Save
| Command::SaveCurrent
| Command::SaveQueue
| Command::Add
| Command::AddCurrent
| Command::Delete
| Command::Back
| Command::Help
| Command::ReloadConfig
| Command::Noop
| Command::Logout
| Command::Reconnect
| Command::Redraw => vec![],
Self::Insert(source) => vec![source.to_string()],
Self::NewPlaylist(name) => vec![name.to_owned()],
Self::Sort(key, direction) => vec![key.to_string(), direction.to_string()],
Self::ShowRecommendations(mode) => vec![mode.to_string()],
Self::Execute(cmd) => vec![cmd.to_owned()],
Self::Quit
| Self::TogglePlay
| Self::Stop
| Self::Previous
| Self::Next
| Self::Clear
| Self::Queue
| Self::PlayNext
| Self::Play
| Self::UpdateLibrary
| Self::Save
| Self::SaveCurrent
| Self::SaveQueue
| Self::Add
| Self::AddCurrent
| Self::Delete
| Self::Back
| Self::Help
| Self::ReloadConfig
| Self::Noop
| Self::Logout
| Self::Reconnect
| Self::Redraw => vec![],
};
repr_tokens.append(&mut extras_args);
write!(f, "{}", repr_tokens.join(" "))
Expand All @@ -237,50 +237,50 @@ impl fmt::Display for Command {
impl Command {
pub fn basename(&self) -> &str {
match self {
Command::Quit => "quit",
Command::TogglePlay => "playpause",
Command::Stop => "stop",
Command::Previous => "previous",
Command::Next => "next",
Command::Clear => "clear",
Command::Queue => "queue",
Command::PlayNext => "playnext",
Command::Play => "play",
Command::UpdateLibrary => "update",
Command::Save => "save",
Command::SaveCurrent => "save current",
Command::SaveQueue => "save queue",
Command::Add => "add",
Command::AddCurrent => "add current",
Command::Delete => "delete",
Command::Focus(_) => "focus",
Command::Seek(_) => "seek",
Command::VolumeUp(_) => "volup",
Command::VolumeDown(_) => "voldown",
Command::Repeat(_) => "repeat",
Command::Shuffle(_) => "shuffle",
Self::Quit => "quit",
Self::TogglePlay => "playpause",
Self::Stop => "stop",
Self::Previous => "previous",
Self::Next => "next",
Self::Clear => "clear",
Self::Queue => "queue",
Self::PlayNext => "playnext",
Self::Play => "play",
Self::UpdateLibrary => "update",
Self::Save => "save",
Self::SaveCurrent => "save current",
Self::SaveQueue => "save queue",
Self::Add => "add",
Self::AddCurrent => "add current",
Self::Delete => "delete",
Self::Focus(_) => "focus",
Self::Seek(_) => "seek",
Self::VolumeUp(_) => "volup",
Self::VolumeDown(_) => "voldown",
Self::Repeat(_) => "repeat",
Self::Shuffle(_) => "shuffle",
#[cfg(feature = "share_clipboard")]
Command::Share(_) => "share",
Command::Back => "back",
Command::Open(_) => "open",
Command::Goto(_) => "goto",
Command::Move(_, _) => "move",
Command::Shift(_, _) => "shift",
Command::Search(_) => "search",
Command::Jump(JumpMode::Previous) => "jumpprevious",
Command::Jump(JumpMode::Next) => "jumpnext",
Command::Jump(JumpMode::Query(_)) => "jump",
Command::Help => "help",
Command::ReloadConfig => "reload",
Command::Noop => "noop",
Command::Insert(_) => "insert",
Command::NewPlaylist(_) => "newplaylist",
Command::Sort(_, _) => "sort",
Command::Logout => "logout",
Command::ShowRecommendations(_) => "similar",
Command::Redraw => "redraw",
Command::Execute(_) => "exec",
Command::Reconnect => "reconnect",
Self::Share(_) => "share",
Self::Back => "back",
Self::Open(_) => "open",
Self::Goto(_) => "goto",
Self::Move(_, _) => "move",
Self::Shift(_, _) => "shift",
Self::Search(_) => "search",
Self::Jump(JumpMode::Previous) => "jumpprevious",
Self::Jump(JumpMode::Next) => "jumpnext",
Self::Jump(JumpMode::Query(_)) => "jump",
Self::Help => "help",
Self::ReloadConfig => "reload",
Self::Noop => "noop",
Self::Insert(_) => "insert",
Self::NewPlaylist(_) => "newplaylist",
Self::Sort(_, _) => "sort",
Self::Logout => "logout",
Self::ShowRecommendations(_) => "similar",
Self::Redraw => "redraw",
Self::Execute(_) => "exec",
Self::Reconnect => "reconnect",
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ impl CommandManager {
library: Arc<Library>,
config: Arc<Config>,
events: EventManager,
) -> CommandManager {
) -> Self {
let bindings = RefCell::new(Self::get_bindings(&config));
CommandManager {
Self {
aliases: HashMap::new(),
bindings,
spotify,
Expand Down
6 changes: 3 additions & 3 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub struct TrackFormat {

impl TrackFormat {
pub fn default() -> Self {
TrackFormat {
Self {
left: Some(String::from("%artists - %title")),
center: Some(String::from("%album")),
right: Some(String::from("%saved %duration")),
Expand All @@ -64,7 +64,7 @@ pub struct NotificationFormat {

impl NotificationFormat {
pub fn default() -> Self {
NotificationFormat {
Self {
title: Some(String::from("%title")),
body: Some(String::from("%artists")),
}
Expand Down Expand Up @@ -163,7 +163,7 @@ pub struct UserState {

impl Default for UserState {
fn default() -> Self {
UserState {
Self {
volume: u16::MAX,
shuffle: false,
repeat: queue::RepeatSetting::None,
Expand Down
4 changes: 2 additions & 2 deletions src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ pub struct EventManager {
}

impl EventManager {
pub fn new(cursive_sink: CbSink) -> EventManager {
pub fn new(cursive_sink: CbSink) -> Self {
let (tx, rx) = unbounded();

EventManager {
Self {
tx,
rx,
cursive_sink,
Expand Down
2 changes: 1 addition & 1 deletion src/ext_traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub trait CursiveExt {
impl CursiveExt for cursive::Cursive {
fn on_layout<F, R>(&mut self, cb: F) -> R
where
F: FnOnce(&mut cursive::Cursive, ViewRef<Layout>) -> R,
F: FnOnce(&mut Self, ViewRef<Layout>) -> R,
{
let layout = self
.find_name::<Layout>("main")
Expand Down
4 changes: 2 additions & 2 deletions src/ipc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl Drop for IpcSocket {
}

impl IpcSocket {
pub fn new(handle: &Handle, path: PathBuf, ev: EventManager) -> io::Result<IpcSocket> {
pub fn new(handle: &Handle, path: PathBuf, ev: EventManager) -> io::Result<Self> {
let path = if path.exists() && Self::is_open_socket(&path) {
let mut new_path = path;
new_path.set_file_name(format!("ncspot.{}.sock", std::process::id()));
Expand All @@ -59,7 +59,7 @@ impl IpcSocket {
Self::worker(listener, ev, rx.clone()).await;
});

Ok(IpcSocket { tx, path })
Ok(Self { tx, path })
}

fn is_open_socket(path: &PathBuf) -> bool {
Expand Down
2 changes: 2 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![deny(clippy::use_self)]

#[macro_use]
extern crate cursive;
#[macro_use]
Expand Down
2 changes: 1 addition & 1 deletion src/model/category.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub struct Category {

impl From<&rspotify::model::Category> for Category {
fn from(c: &rspotify::model::Category) -> Self {
Category {
Self {
id: c.id.clone(),
name: c.name.clone(),
}
Expand Down
Loading

0 comments on commit 3e15f2b

Please sign in to comment.