Skip to content

Commit e4598d4

Browse files
committed
chore: bump rust edition and fix lints
1 parent d0d9f80 commit e4598d4

File tree

9 files changed

+45
-53
lines changed

9 files changed

+45
-53
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
[package]
22
authors = ["Simon Persson <[email protected]>", "Sven Lechner <[email protected]>", "eladyn <[email protected]>"]
3-
edition = "2018"
3+
edition = "2024"
44
name = "spotifyd"
55
description = "A Spotify daemon"
66
repository = "https://github.com/Spotifyd/spotifyd"
77
license = "GPL-3.0-only"
88
version = "0.4.1"
99
resolver = "2"
10-
rust-version = "1.82"
10+
rust-version = "1.85"
1111

1212
[dependencies]
1313
alsa = { version = "0.9.1", optional = true }

src/config.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
use crate::utils;
22
use clap::{
3-
builder::{IntoResettable, PossibleValuesParser, TypedValueParser, ValueParser},
43
Args, Parser, Subcommand, ValueEnum,
4+
builder::{IntoResettable, PossibleValuesParser, TypedValueParser, ValueParser},
55
};
66
use color_eyre::{
7-
eyre::{bail, Context},
87
Report,
8+
eyre::{Context, bail},
99
};
1010
use directories::ProjectDirs;
1111
use gethostname::gethostname;
1212
use librespot_core::{cache::Cache, config::DeviceType as LSDeviceType, config::SessionConfig};
1313
use librespot_playback::{
1414
audio_backend,
1515
config::{AudioFormat as LSAudioFormat, Bitrate as LSBitrate, PlayerConfig},
16-
dither::{mk_ditherer, DithererBuilder, TriangularDitherer},
16+
dither::{DithererBuilder, TriangularDitherer, mk_ditherer},
1717
};
1818
use log::{debug, error, info, warn};
1919
use serde::{
20-
de::{self, Error, Unexpected},
2120
Deserialize, Deserializer,
21+
de::{self, Error, Unexpected},
2222
};
2323
use sha1::{Digest, Sha1};
2424
use std::{
@@ -488,10 +488,14 @@ impl CliConfig {
488488
if let Some(problem) = get_known_config_problem(&path) {
489489
match problem {
490490
KnownConfigProblem::MissingFeature(feature) => {
491-
warn!("The config key '{path}' is ignored, because the feature '{feature}' is missing in this build");
491+
warn!(
492+
"The config key '{path}' is ignored, because the feature '{feature}' is missing in this build"
493+
);
492494
}
493495
KnownConfigProblem::UsernamePassword => {
494-
warn!("The config key '{path}' is ignored, because authentication with username and password is no longer supported by Spotify. Please use `spotifyd authenticate` instead");
496+
warn!(
497+
"The config key '{path}' is ignored, because authentication with username and password is no longer supported by Spotify. Please use `spotifyd authenticate` instead"
498+
);
495499
}
496500
}
497501
} else {

src/dbus_mpris.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
use crate::config::DBusType;
2-
use chrono::{prelude::*, Duration};
2+
use chrono::{Duration, prelude::*};
33
use dbus::{
4+
MethodErr,
45
arg::{RefArg, Variant},
56
channel::{MatchingReceiver, Sender},
67
message::{MatchRule, SignalArgs},
78
nonblock::stdintf::org_freedesktop_dbus::PropertiesPropertiesChanged,
8-
MethodErr,
99
};
1010
use dbus_crossroads::{Crossroads, IfaceToken};
1111
use dbus_tokio::connection::{self, IOResourceError};
1212
use futures::{
13-
task::{Context, Poll},
1413
Future,
14+
task::{Context, Poll},
1515
};
1616
use librespot_connect::spirc::{Spirc, SpircLoadCommand};
17-
use librespot_core::{spotify_id::SpotifyItemType, Session, SpotifyId};
17+
use librespot_core::{Session, SpotifyId, spotify_id::SpotifyItemType};
1818
use librespot_metadata::audio::AudioItem;
1919
use librespot_playback::player::PlayerEvent;
2020
use librespot_protocol::spirc::TrackRef;
@@ -30,8 +30,8 @@ use time::format_description::well_known::Iso8601;
3030
use tokio::{
3131
runtime::Handle,
3232
sync::{
33-
mpsc::{UnboundedReceiver, UnboundedSender},
3433
Mutex,
34+
mpsc::{UnboundedReceiver, UnboundedSender},
3535
},
3636
};
3737

@@ -386,11 +386,13 @@ impl CurrentState {
386386
Self(RwLock::new(inner))
387387
}
388388

389-
fn read(&self) -> Result<std::sync::RwLockReadGuard<CurrentStateInner>, StatePoisonError> {
389+
fn read(&self) -> Result<std::sync::RwLockReadGuard<'_, CurrentStateInner>, StatePoisonError> {
390390
self.0.read().map_err(|_| StatePoisonError)
391391
}
392392

393-
fn write(&self) -> Result<std::sync::RwLockWriteGuard<CurrentStateInner>, StatePoisonError> {
393+
fn write(
394+
&self,
395+
) -> Result<std::sync::RwLockWriteGuard<'_, CurrentStateInner>, StatePoisonError> {
394396
self.0.write().map_err(|_| StatePoisonError)
395397
}
396398
}
@@ -835,7 +837,7 @@ fn register_player_interface(
835837
mode => {
836838
return Err(dbus::MethodErr::failed(&format!(
837839
"unsupported repeat mode: {mode}"
838-
)))
840+
)));
839841
}
840842
};
841843
local_spirc

src/error.rs

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,4 @@
1-
use std::{
2-
error::Error as StdError,
3-
fmt::{self, Display},
4-
};
5-
6-
#[derive(Clone, Debug)]
7-
pub struct ParseError(String);
8-
9-
impl fmt::Display for ParseError {
10-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
11-
write!(f, "failed to parse config entry: {}", self.0)
12-
}
13-
}
14-
15-
impl StdError for ParseError {
16-
fn source(&self) -> Option<&(dyn StdError + 'static)> {
17-
None
18-
}
19-
}
1+
use std::fmt::{self, Display};
202

213
/// This crate's error type.
224
#[derive(Debug)]
@@ -90,12 +72,12 @@ impl Display for ErrorKind {
9072
match self {
9173
ErrorKind::Subprocess { cmd, msg, shell } => match msg {
9274
Message::None => write!(f, "Failed to execute {:?} using {:?}.", cmd, shell),
93-
Message::Error(ref e) => write!(
75+
Message::Error(e) => write!(
9476
f,
9577
"Failed to execute {:?} using {:?}. Error: {}",
9678
cmd, shell, e
9779
),
98-
Message::String(ref s) => write!(
80+
Message::String(s) => write!(
9981
f,
10082
"Failed to execute {:?} using {:?}. Error: {}",
10183
cmd, shell, s

src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use config::ExecutionMode;
77
#[cfg(unix)]
88
use daemonize::Daemonize;
99
use fern::colors::ColoredLevelConfig;
10-
use log::{info, trace, LevelFilter};
10+
use log::{LevelFilter, info, trace};
1111
use oauth::run_oauth;
1212
#[cfg(target_os = "openbsd")]
1313
use pledge::pledge;
@@ -176,7 +176,7 @@ fn run_daemon(mut cli_config: CliConfig) -> eyre::Result<()> {
176176
#[cfg(target_os = "windows")]
177177
{
178178
use std::os::windows::process::CommandExt;
179-
use std::process::{exit, Command};
179+
use std::process::{Command, exit};
180180

181181
let mut args = std::env::args().collect::<Vec<_>>();
182182
args.remove(0);

src/main_loop.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,14 @@ use futures::future::Either;
99
#[cfg(not(feature = "dbus_mpris"))]
1010
use futures::future::Pending;
1111
use futures::{
12-
self,
12+
self, Future, FutureExt, StreamExt,
1313
future::{self, Fuse, FusedFuture},
1414
stream::Peekable,
15-
Future, FutureExt, StreamExt,
1615
};
1716
use librespot_connect::{config::ConnectConfig, spirc::Spirc};
1817
use librespot_core::{
19-
authentication::Credentials, cache::Cache, config::DeviceType, session::Session, Error,
20-
SessionConfig,
18+
Error, SessionConfig, authentication::Credentials, cache::Cache, config::DeviceType,
19+
session::Session,
2120
};
2221
use librespot_discovery::Discovery;
2322
use librespot_playback::{
@@ -101,7 +100,9 @@ struct ConnectionInfo<SpircTask: Future<Output = ()>> {
101100
}
102101

103102
impl MainLoop {
104-
async fn get_connection(&mut self) -> Result<ConnectionInfo<impl Future<Output = ()>>, Error> {
103+
async fn get_connection(
104+
&mut self,
105+
) -> Result<ConnectionInfo<impl Future<Output = ()> + use<>>, Error> {
105106
let creds = self.credentials_provider.get_credentials().await;
106107

107108
let mut connection_backoff = Backoff::default();
@@ -141,7 +142,7 @@ impl MainLoop {
141142
session,
142143
player,
143144
spirc_task,
144-
})
145+
});
145146
}
146147
Err(err) => {
147148
let Ok(backoff) = connection_backoff.next_backoff() else {

src/oauth.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
use color_eyre::{
2-
eyre::{self, Context as _},
32
Section as _,
3+
eyre::{self, Context as _},
44
};
55
use librespot_core::SessionConfig;
6-
use librespot_core::{authentication::Credentials, Session};
6+
use librespot_core::{Session, authentication::Credentials};
77
use log::info;
88
use tokio::runtime::Runtime;
99

10-
use crate::{config::CliConfig, setup_logger, LogTarget};
10+
use crate::{LogTarget, config::CliConfig, setup_logger};
1111

1212
pub(crate) fn run_oauth(mut cli_config: CliConfig, oauth_port: u16) -> eyre::Result<()> {
1313
setup_logger(LogTarget::Terminal, cli_config.verbose)?;

src/setup.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::{
55
main_loop::{self, CredentialsProvider},
66
utils::Backoff,
77
};
8-
use color_eyre::{eyre::eyre, Section};
8+
use color_eyre::{Section, eyre::eyre};
99
use futures::StreamExt as _;
1010
use librespot_playback::{
1111
audio_backend::{self},
@@ -116,9 +116,9 @@ pub(crate) fn initial_state(
116116
(None, Some(creds)) => CredentialsProvider::CredentialsOnly(creds),
117117
(None, None) => {
118118
return Err(
119-
eyre!("Discovery unavailable and no credentials found.").with_suggestion(|| {
120-
"Try enabling discovery or logging in first with `spotifyd authenticate`."
121-
}),
119+
eyre!("Discovery unavailable and no credentials found.").with_suggestion(
120+
|| "Try enabling discovery or logging in first with `spotifyd authenticate`.",
121+
),
122122
);
123123
}
124124
};

src/utils.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,10 @@ mod tests {
139139
fn test_envvar_discovery() {
140140
init_logger();
141141

142-
env::set_var("SHELL", "fantasy_shell");
142+
// SAFETY: this is part of the single-threaded tests
143+
unsafe {
144+
env::set_var("SHELL", "fantasy_shell");
145+
}
143146

144147
let shell = get_shell().unwrap();
145148
assert_eq!(shell, "fantasy_shell");

0 commit comments

Comments
 (0)