Skip to content

Commit 6288e7e

Browse files
committed
refactor: update to Rust 1.85 and edition 2024, use inline log args
- Update MSRV to 1.85 and Rust edition to 2024. - Refactor all logging macros to use inline argument formatting. - Fix import order in main.rs and examples. - Add async environment variable setter to main.rs as safe facade.
1 parent 0aec38b commit 6288e7e

30 files changed

Lines changed: 416 additions & 445 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Changed
1111

12-
- [core] MSRV is now 1.81 (breaking)
12+
- [core] MSRV is now 1.85 with Rust edition 2024 (breaking)
1313
- [core] AP connect and handshake have a combined 5 second timeout.
1414
- [core] `stream_from_cdn` now accepts the URL as `TryInto<Uri>` instead of `CdnUrl` (breaking)
1515
- [connect] Replaced `has_volume_ctrl` with `disable_volume` in `ConnectConfig` (breaking)

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
[package]
22
name = "librespot"
33
version = "0.6.0-dev"
4-
rust-version = "1.81"
4+
rust-version = "1.85"
55
authors = ["Librespot Org"]
66
license = "MIT"
77
description = "An open source client library for Spotify, with support for Spotify Connect"
88
keywords = ["spotify"]
99
repository = "https://github.com/librespot-org/librespot"
1010
readme = "README.md"
11-
edition = "2021"
11+
edition = "2024"
1212

1313
[workspace]
1414

@@ -126,4 +126,4 @@ assets = [
126126
]
127127

128128
[workspace.package]
129-
rust-version = "1.81"
129+
rust-version = "1.85"

audio/src/fetch/mod.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -366,11 +366,11 @@ impl AudioFile {
366366
bytes_per_second: usize,
367367
) -> Result<AudioFile, Error> {
368368
if let Some(file) = session.cache().and_then(|cache| cache.file(file_id)) {
369-
debug!("File {} already in cache", file_id);
369+
debug!("File {file_id} already in cache");
370370
return Ok(AudioFile::Cached(file));
371371
}
372372

373-
debug!("Downloading file {}", file_id);
373+
debug!("Downloading file {file_id}");
374374

375375
let (complete_tx, complete_rx) = oneshot::channel();
376376

@@ -379,14 +379,14 @@ impl AudioFile {
379379

380380
let session_ = session.clone();
381381
session.spawn(complete_rx.map_ok(move |mut file| {
382-
debug!("Downloading file {} complete", file_id);
382+
debug!("Downloading file {file_id} complete");
383383

384384
if let Some(cache) = session_.cache() {
385385
if let Some(cache_id) = cache.file_path(file_id) {
386386
if let Err(e) = cache.save_file(file_id, &mut file) {
387-
error!("Error caching file {} to {:?}: {}", file_id, cache_id, e);
387+
error!("Error caching file {file_id} to {cache_id:?}: {e}");
388388
} else {
389-
debug!("File {} cached to {:?}", file_id, cache_id);
389+
debug!("File {file_id} cached to {cache_id:?}");
390390
}
391391
}
392392
}
@@ -465,14 +465,11 @@ impl AudioFileStreaming {
465465
)));
466466
};
467467

468-
trace!("Streaming from {}", url);
468+
trace!("Streaming from {url}");
469469

470470
let code = response.status();
471471
if code != StatusCode::PARTIAL_CONTENT {
472-
debug!(
473-
"Opening audio file expected partial content but got: {}",
474-
code
475-
);
472+
debug!("Opening audio file expected partial content but got: {code}");
476473
return Err(AudioFileError::StatusCode(code).into());
477474
}
478475

connect/src/spirc.rs

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ impl Spirc {
166166
}
167167

168168
let spirc_id = SPIRC_COUNTER.fetch_add(1, Ordering::AcqRel);
169-
debug!("new Spirc[{}]", spirc_id);
169+
debug!("new Spirc[{spirc_id}]");
170170

171171
let connect_state = ConnectState::new(config, &session);
172172

@@ -446,14 +446,14 @@ impl SpircTask {
446446
cluster_update = self.connect_state_update.next() => unwrap! {
447447
cluster_update,
448448
match |cluster_update| if let Err(e) = self.handle_cluster_update(cluster_update).await {
449-
error!("could not dispatch connect state update: {}", e);
449+
error!("could not dispatch connect state update: {e}");
450450
}
451451
},
452452
// main dealer request handling (dealer expects an answer)
453453
request = self.connect_state_command.next() => unwrap! {
454454
request,
455455
|request| if let Err(e) = self.handle_connect_state_request(request).await {
456-
error!("couldn't handle connect state command: {}", e);
456+
error!("couldn't handle connect state command: {e}");
457457
}
458458
},
459459
// volume request handling is send separately (it's more like a fire forget)
@@ -491,12 +491,12 @@ impl SpircTask {
491491
},
492492
cmd = async { commands?.recv().await }, if commands.is_some() => if let Some(cmd) = cmd {
493493
if let Err(e) = self.handle_command(cmd).await {
494-
debug!("could not dispatch command: {}", e);
494+
debug!("could not dispatch command: {e}");
495495
}
496496
},
497497
event = async { player_events?.recv().await }, if player_events.is_some() => if let Some(event) = event {
498498
if let Err(e) = self.handle_player_event(event) {
499-
error!("could not dispatch player event: {}", e);
499+
error!("could not dispatch player event: {e}");
500500
}
501501
},
502502
_ = async { sleep(UPDATE_STATE_DELAY).await }, if self.update_state => {
@@ -606,7 +606,7 @@ impl SpircTask {
606606
}
607607

608608
async fn handle_command(&mut self, cmd: SpircCommand) -> Result<(), Error> {
609-
trace!("Received SpircCommand::{:?}", cmd);
609+
trace!("Received SpircCommand::{cmd:?}");
610610
match cmd {
611611
SpircCommand::Shutdown => {
612612
trace!("Received SpircCommand::Shutdown");
@@ -618,16 +618,15 @@ impl SpircTask {
618618
}
619619
}
620620
SpircCommand::Activate if !self.connect_state.is_active() => {
621-
trace!("Received SpircCommand::{:?}", cmd);
621+
trace!("Received SpircCommand::{cmd:?}");
622622
self.handle_activate();
623623
return self.notify().await;
624624
}
625-
SpircCommand::Activate => warn!(
626-
"SpircCommand::{:?} will be ignored while already active",
627-
cmd
628-
),
625+
SpircCommand::Activate => {
626+
warn!("SpircCommand::{cmd:?} will be ignored while already active")
627+
}
629628
_ if !self.connect_state.is_active() => {
630-
warn!("SpircCommand::{:?} will be ignored while Not Active", cmd)
629+
warn!("SpircCommand::{cmd:?} will be ignored while Not Active")
631630
}
632631
SpircCommand::Disconnect { pause } => {
633632
if pause {
@@ -787,7 +786,7 @@ impl SpircTask {
787786
}
788787

789788
async fn handle_connection_id_update(&mut self, connection_id: String) -> Result<(), Error> {
790-
trace!("Received connection ID update: {:?}", connection_id);
789+
trace!("Received connection ID update: {connection_id:?}");
791790
self.session.set_connection_id(&connection_id);
792791

793792
let cluster = match self
@@ -837,7 +836,7 @@ impl SpircTask {
837836
}
838837

839838
fn handle_user_attributes_update(&mut self, update: UserAttributesUpdate) {
840-
trace!("Received attributes update: {:#?}", update);
839+
trace!("Received attributes update: {update:#?}");
841840
let attributes: UserAttributes = update
842841
.pairs
843842
.iter()
@@ -863,12 +862,7 @@ impl SpircTask {
863862
};
864863
self.session.set_user_attribute(key, new_value);
865864

866-
trace!(
867-
"Received attribute mutation, {} was {} is now {}",
868-
key,
869-
old_value,
870-
new_value
871-
);
865+
trace!("Received attribute mutation, {key} was {old_value} is now {new_value}");
872866

873867
if key == "filter-explicit-content" && new_value == "1" {
874868
self.player
@@ -882,10 +876,7 @@ impl SpircTask {
882876
self.add_autoplay_resolving_when_required()
883877
}
884878
} else {
885-
trace!(
886-
"Received attribute mutation for {} but key was not found!",
887-
key
888-
);
879+
trace!("Received attribute mutation for {key} but key was not found!");
889880
}
890881
}
891882
}
@@ -1743,7 +1734,7 @@ impl SpircTask {
17431734
}
17441735

17451736
fn set_volume(&mut self, volume: u16) {
1746-
debug!("SpircTask::set_volume({})", volume);
1737+
debug!("SpircTask::set_volume({volume})");
17471738

17481739
let old_volume = self.connect_state.device_info().volume;
17491740
let new_volume = volume as u32;

core/src/apresolve.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ impl ApResolver {
108108
if inner.data.is_any_empty() {
109109
warn!("Failed to resolve all access points, using fallbacks");
110110
if let Some(error) = error {
111-
warn!("Resolve access points error: {}", error);
111+
warn!("Resolve access points error: {error}");
112112
}
113113

114114
let fallback = self.parse_resolve_to_access_points(ApResolveData::fallback());

core/src/audio_key.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,7 @@ impl AudioKeyManager {
7070
.map_err(|_| AudioKeyError::Channel)?
7171
}
7272
_ => {
73-
trace!(
74-
"Did not expect {:?} AES key packet with data {:#?}",
75-
cmd,
76-
data
77-
);
73+
trace!("Did not expect {cmd:?} AES key packet with data {data:#?}");
7874
return Err(AudioKeyError::Packet(cmd as u8).into());
7975
}
8076
}

core/src/cache.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ impl FsSizeLimiter {
141141
let list_dir = match fs::read_dir(path) {
142142
Ok(list_dir) => list_dir,
143143
Err(e) => {
144-
warn!("Could not read directory {:?} in cache dir: {}", path, e);
144+
warn!("Could not read directory {path:?} in cache dir: {e}");
145145
return;
146146
}
147147
};
@@ -150,7 +150,7 @@ impl FsSizeLimiter {
150150
let entry = match entry {
151151
Ok(entry) => entry,
152152
Err(e) => {
153-
warn!("Could not directory {:?} in cache dir: {}", path, e);
153+
warn!("Could not directory {path:?} in cache dir: {e}");
154154
return;
155155
}
156156
};
@@ -166,7 +166,7 @@ impl FsSizeLimiter {
166166
limiter.add(&path, size, access_time);
167167
}
168168
Err(e) => {
169-
warn!("Could not read file {:?} in cache dir: {}", path, e)
169+
warn!("Could not read file {path:?} in cache dir: {e}")
170170
}
171171
}
172172
}
@@ -213,15 +213,15 @@ impl FsSizeLimiter {
213213

214214
let res = fs::remove_file(&file);
215215
if let Err(e) = res {
216-
warn!("Could not remove file {:?} from cache dir: {}", file, e);
216+
warn!("Could not remove file {file:?} from cache dir: {e}");
217217
last_error = Some(e);
218218
} else {
219219
count += 1;
220220
}
221221
}
222222

223223
if count > 0 {
224-
info!("Removed {} cache files.", count);
224+
info!("Removed {count} cache files.");
225225
}
226226

227227
if let Some(err) = last_error {
@@ -317,7 +317,7 @@ impl Cache {
317317
// If the file did not exist, the file was probably not written
318318
// before. Otherwise, log the error.
319319
if e.kind != ErrorKind::NotFound {
320-
warn!("Error reading credentials from cache: {}", e);
320+
warn!("Error reading credentials from cache: {e}");
321321
}
322322
None
323323
}
@@ -332,7 +332,7 @@ impl Cache {
332332
});
333333

334334
if let Err(e) = result {
335-
warn!("Cannot save credentials to cache: {}", e)
335+
warn!("Cannot save credentials to cache: {e}")
336336
}
337337
}
338338
}
@@ -351,7 +351,7 @@ impl Cache {
351351
Ok(v) => Some(v),
352352
Err(e) => {
353353
if e.kind != ErrorKind::NotFound {
354-
warn!("Error reading volume from cache: {}", e);
354+
warn!("Error reading volume from cache: {e}");
355355
}
356356
None
357357
}
@@ -362,7 +362,7 @@ impl Cache {
362362
if let Some(ref location) = self.volume_location {
363363
let result = File::create(location).and_then(|mut file| write!(file, "{volume}"));
364364
if let Err(e) = result {
365-
warn!("Cannot save volume to cache: {}", e);
365+
warn!("Cannot save volume to cache: {e}");
366366
}
367367
}
368368
}
@@ -375,7 +375,7 @@ impl Cache {
375375
path
376376
}),
377377
Err(e) => {
378-
warn!("Invalid FileId: {}", e);
378+
warn!("Invalid FileId: {e}");
379379
None
380380
}
381381
}
@@ -387,14 +387,14 @@ impl Cache {
387387
Ok(file) => {
388388
if let Some(limiter) = self.size_limiter.as_deref() {
389389
if !limiter.touch(&path) {
390-
error!("limiter could not touch {:?}", path);
390+
error!("limiter could not touch {path:?}");
391391
}
392392
}
393393
Some(file)
394394
}
395395
Err(e) => {
396396
if e.kind() != io::ErrorKind::NotFound {
397-
warn!("Error reading file from cache: {}", e)
397+
warn!("Error reading file from cache: {e}")
398398
}
399399
None
400400
}

core/src/cdn_url.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ impl CdnUrl {
7373

7474
let cdn_url = Self { file_id, urls };
7575

76-
trace!("Resolved CDN storage: {:#?}", cdn_url);
76+
trace!("Resolved CDN storage: {cdn_url:#?}");
7777

7878
Ok(cdn_url)
7979
}

core/src/connection/mod.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,7 @@ pub async fn authenticate(
186186
Err(error_data.into())
187187
}
188188
_ => {
189-
trace!(
190-
"Did not expect {:?} AES key packet with data {:#?}",
191-
cmd,
192-
data
193-
);
189+
trace!("Did not expect {cmd:?} AES key packet with data {data:#?}");
194190
Err(AuthenticationError::Packet(cmd))
195191
}
196192
};

0 commit comments

Comments
 (0)