1
0
Fork 0
mirror of https://github.com/librespot-org/librespot.git synced 2025-10-03 01:39:28 +02:00

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.
This commit is contained in:
Roderick van Domburg 2025-08-13 16:19:39 +02:00
parent 0aec38b07a
commit 6288e7e03c
No known key found for this signature in database
GPG key ID: 607FA06CB5236AE0
30 changed files with 419 additions and 448 deletions

View file

@ -108,7 +108,7 @@ impl ApResolver {
if inner.data.is_any_empty() {
warn!("Failed to resolve all access points, using fallbacks");
if let Some(error) = error {
warn!("Resolve access points error: {}", error);
warn!("Resolve access points error: {error}");
}
let fallback = self.parse_resolve_to_access_points(ApResolveData::fallback());

View file

@ -70,11 +70,7 @@ impl AudioKeyManager {
.map_err(|_| AudioKeyError::Channel)?
}
_ => {
trace!(
"Did not expect {:?} AES key packet with data {:#?}",
cmd,
data
);
trace!("Did not expect {cmd:?} AES key packet with data {data:#?}");
return Err(AudioKeyError::Packet(cmd as u8).into());
}
}

View file

@ -141,7 +141,7 @@ impl FsSizeLimiter {
let list_dir = match fs::read_dir(path) {
Ok(list_dir) => list_dir,
Err(e) => {
warn!("Could not read directory {:?} in cache dir: {}", path, e);
warn!("Could not read directory {path:?} in cache dir: {e}");
return;
}
};
@ -150,7 +150,7 @@ impl FsSizeLimiter {
let entry = match entry {
Ok(entry) => entry,
Err(e) => {
warn!("Could not directory {:?} in cache dir: {}", path, e);
warn!("Could not directory {path:?} in cache dir: {e}");
return;
}
};
@ -166,7 +166,7 @@ impl FsSizeLimiter {
limiter.add(&path, size, access_time);
}
Err(e) => {
warn!("Could not read file {:?} in cache dir: {}", path, e)
warn!("Could not read file {path:?} in cache dir: {e}")
}
}
}
@ -213,7 +213,7 @@ impl FsSizeLimiter {
let res = fs::remove_file(&file);
if let Err(e) = res {
warn!("Could not remove file {:?} from cache dir: {}", file, e);
warn!("Could not remove file {file:?} from cache dir: {e}");
last_error = Some(e);
} else {
count += 1;
@ -221,7 +221,7 @@ impl FsSizeLimiter {
}
if count > 0 {
info!("Removed {} cache files.", count);
info!("Removed {count} cache files.");
}
if let Some(err) = last_error {
@ -317,7 +317,7 @@ impl Cache {
// If the file did not exist, the file was probably not written
// before. Otherwise, log the error.
if e.kind != ErrorKind::NotFound {
warn!("Error reading credentials from cache: {}", e);
warn!("Error reading credentials from cache: {e}");
}
None
}
@ -332,7 +332,7 @@ impl Cache {
});
if let Err(e) = result {
warn!("Cannot save credentials to cache: {}", e)
warn!("Cannot save credentials to cache: {e}")
}
}
}
@ -351,7 +351,7 @@ impl Cache {
Ok(v) => Some(v),
Err(e) => {
if e.kind != ErrorKind::NotFound {
warn!("Error reading volume from cache: {}", e);
warn!("Error reading volume from cache: {e}");
}
None
}
@ -362,7 +362,7 @@ impl Cache {
if let Some(ref location) = self.volume_location {
let result = File::create(location).and_then(|mut file| write!(file, "{volume}"));
if let Err(e) = result {
warn!("Cannot save volume to cache: {}", e);
warn!("Cannot save volume to cache: {e}");
}
}
}
@ -375,7 +375,7 @@ impl Cache {
path
}),
Err(e) => {
warn!("Invalid FileId: {}", e);
warn!("Invalid FileId: {e}");
None
}
}
@ -387,14 +387,14 @@ impl Cache {
Ok(file) => {
if let Some(limiter) = self.size_limiter.as_deref() {
if !limiter.touch(&path) {
error!("limiter could not touch {:?}", path);
error!("limiter could not touch {path:?}");
}
}
Some(file)
}
Err(e) => {
if e.kind() != io::ErrorKind::NotFound {
warn!("Error reading file from cache: {}", e)
warn!("Error reading file from cache: {e}")
}
None
}

View file

@ -73,7 +73,7 @@ impl CdnUrl {
let cdn_url = Self { file_id, urls };
trace!("Resolved CDN storage: {:#?}", cdn_url);
trace!("Resolved CDN storage: {cdn_url:#?}");
Ok(cdn_url)
}

View file

@ -186,11 +186,7 @@ pub async fn authenticate(
Err(error_data.into())
}
_ => {
trace!(
"Did not expect {:?} AES key packet with data {:#?}",
cmd,
data
);
trace!("Did not expect {cmd:?} AES key packet with data {data:#?}");
Err(AuthenticationError::Packet(cmd))
}
};

View file

@ -89,7 +89,7 @@ impl Responder {
.to_string();
if let Err(e) = self.tx.send(WsMessage::Text(response.into())) {
warn!("Wasn't able to reply to dealer request: {}", e);
warn!("Wasn't able to reply to dealer request: {e}");
}
}
@ -452,7 +452,7 @@ impl Dealer {
if let Some(handle) = self.handle.take() {
if let Err(e) = CancelOnDrop(handle).await {
error!("error aborting dealer operations: {}", e);
error!("error aborting dealer operations: {e}");
}
}
}
@ -524,13 +524,13 @@ async fn connect(
Ok(close_frame) => ws_tx.send(WsMessage::Close(close_frame)).await,
Err(WsError::AlreadyClosed) | Err(WsError::ConnectionClosed) => ws_tx.flush().await,
Err(e) => {
warn!("Dealer finished with an error: {}", e);
warn!("Dealer finished with an error: {e}");
ws_tx.send(WsMessage::Close(None)).await
}
};
if let Err(e) = result {
warn!("Error while closing websocket: {}", e);
warn!("Error while closing websocket: {e}");
}
debug!("Dropping send task");
@ -565,7 +565,7 @@ async fn connect(
_ => (), // tungstenite handles Close and Ping automatically
},
Some(Err(e)) => {
warn!("Websocket connection failed: {}", e);
warn!("Websocket connection failed: {e}");
break;
}
None => {
@ -648,13 +648,13 @@ where
() = shared.closed() => break,
r = t0 => {
if let Err(e) = r {
error!("timeout on task 0: {}", e);
error!("timeout on task 0: {e}");
}
tasks.0.take();
},
r = t1 => {
if let Err(e) = r {
error!("timeout on task 1: {}", e);
error!("timeout on task 1: {e}");
}
tasks.1.take();
}
@ -671,7 +671,7 @@ where
match connect(&url, proxy.as_ref(), &shared).await {
Ok((s, r)) => tasks = (init_task(s), init_task(r)),
Err(e) => {
error!("Error while connecting: {}", e);
error!("Error while connecting: {e}");
tokio::time::sleep(RECONNECT_INTERVAL).await;
}
}

View file

@ -124,7 +124,7 @@ impl HttpClient {
);
let user_agent = HeaderValue::from_str(user_agent_str).unwrap_or_else(|err| {
error!("Invalid user agent <{}>: {}", user_agent_str, err);
error!("Invalid user agent <{user_agent_str}>: {err}");
HeaderValue::from_static(FALLBACK_USER_AGENT)
});
@ -176,7 +176,7 @@ impl HttpClient {
}
pub async fn request(&self, req: Request<Bytes>) -> Result<Response<Incoming>, Error> {
debug!("Requesting {}", req.uri().to_string());
debug!("Requesting {}", req.uri());
// `Request` does not implement `Clone` because its `Body` may be a single-shot stream.
// As correct as that may be technically, we now need all this boilerplate to clone it

View file

@ -199,7 +199,7 @@ impl Login5Manager {
inner.auth_token.clone()
});
trace!("Got auth token: {:?}", auth_token);
trace!("Got auth token: {auth_token:?}");
token.ok_or(Login5Error::NoStoredCredentials.into())
}

View file

@ -131,12 +131,12 @@ impl MercuryManager {
Ok(mut sub) => {
let sub_uri = sub.take_uri();
debug!("subscribed sub_uri={}", sub_uri);
debug!("subscribed sub_uri={sub_uri}");
inner.subscriptions.push((sub_uri, tx.clone()));
}
Err(e) => {
error!("could not subscribe to {}: {}", uri, e);
error!("could not subscribe to {uri}: {e}");
}
}
}
@ -163,7 +163,7 @@ impl MercuryManager {
manager.lock(move |inner| {
if !inner.invalid {
debug!("listening to uri={}", uri);
debug!("listening to uri={uri}");
inner.subscriptions.push((uri, tx));
}
});
@ -283,14 +283,14 @@ impl MercuryManager {
Ok(())
} else {
debug!("unknown subscription uri={}", &response.uri);
trace!("response pushed over Mercury: {:?}", response);
trace!("response pushed over Mercury: {response:?}");
Err(MercuryError::Response(response).into())
}
} else if let Some(cb) = pending.callback {
cb.send(Ok(response)).map_err(|_| MercuryError::Channel)?;
Ok(())
} else {
error!("can't handle Mercury response: {:?}", response);
error!("can't handle Mercury response: {response:?}");
Err(MercuryError::Response(response).into())
}
}

View file

@ -273,7 +273,7 @@ impl Session {
let session_weak = self.weak();
tokio::spawn(async move {
if let Err(e) = sender_task.await {
error!("{}", e);
error!("{e}");
if let Some(session) = session_weak.try_upgrade() {
if !session.is_invalid() {
session.shutdown();
@ -360,7 +360,7 @@ impl Session {
fn check_catalogue(attributes: &UserAttributes) {
if let Some(account_type) = attributes.get("type") {
if account_type != "premium" {
error!("librespot does not support {:?} accounts.", account_type);
error!("librespot does not support {account_type:?} accounts.");
info!("Please support Spotify and your artists and sign up for a premium account.");
// TODO: logout instead of exiting
@ -566,7 +566,7 @@ impl KeepAliveState {
.map(|t| t.as_secs_f64())
.unwrap_or(f64::INFINITY);
trace!("keep-alive state: {:?}, timeout in {:.1}", self, delay);
trace!("keep-alive state: {self:?}, timeout in {delay:.1}");
}
}
@ -619,7 +619,7 @@ where
let cmd = match packet_type {
Some(cmd) => cmd,
None => {
trace!("Ignoring unknown packet {:x}", cmd);
trace!("Ignoring unknown packet {cmd:x}");
return Err(SessionError::Packet(cmd).into());
}
};
@ -667,7 +667,7 @@ where
}
Some(CountryCode) => {
let country = String::from_utf8(data.as_ref().to_owned())?;
info!("Country: {:?}", country);
info!("Country: {country:?}");
session.0.data.write().user_data.country = country;
Ok(())
}
@ -710,7 +710,7 @@ where
}
}
trace!("Received product info: {:#?}", user_attributes);
trace!("Received product info: {user_attributes:#?}");
Session::check_catalogue(&user_attributes);
session.0.data.write().user_data.attributes = user_attributes;
@ -721,7 +721,7 @@ where
| Some(UnknownDataAllZeros)
| Some(LicenseVersion) => Ok(()),
_ => {
trace!("Ignoring {:?} packet with data {:#?}", cmd, data);
trace!("Ignoring {cmd:?} packet with data {data:#?}");
Err(SessionError::Packet(cmd as u8).into())
}
}
@ -749,7 +749,7 @@ where
Poll::Ready(Some(Ok((cmd, data)))) => {
let result = self.as_mut().dispatch(&session, cmd, data);
if let Err(e) = result {
debug!("could not dispatch command: {}", e);
debug!("could not dispatch command: {e}");
}
}
Poll::Ready(None) => {

View file

@ -7,7 +7,7 @@ use crate::proxytunnel;
pub async fn connect(host: &str, port: u16, proxy: Option<&Url>) -> io::Result<TcpStream> {
let socket = if let Some(proxy_url) = proxy {
info!("Using proxy \"{}\"", proxy_url);
info!("Using proxy \"{proxy_url}\"");
let socket_addr = proxy_url.socket_addrs(|| None).and_then(|addrs| {
addrs.into_iter().next().ok_or_else(|| {

View file

@ -311,20 +311,12 @@ impl SpClient {
continue;
}
Err(e) => {
trace!(
"Answer not accepted {}/{}: {}",
count,
MAX_TRIES,
e
);
trace!("Answer not accepted {count}/{MAX_TRIES}: {e}");
}
}
}
Err(e) => trace!(
"Unable to solve hash cash challenge {}/{}: {}",
count,
MAX_TRIES,
e
"Unable to solve hash cash challenge {count}/{MAX_TRIES}: {e}"
),
}
@ -373,7 +365,7 @@ impl SpClient {
inner.client_token = Some(client_token);
});
trace!("Got client token: {:?}", granted_token);
trace!("Got client token: {granted_token:?}");
Ok(access_token)
}
@ -542,7 +534,7 @@ impl SpClient {
}
}
debug!("Error was: {:?}", last_response);
debug!("Error was: {last_response:?}");
}
last_response

View file

@ -86,8 +86,7 @@ impl TokenProvider {
}
trace!(
"Requested token in scopes {:?} unavailable or expired, requesting new token.",
scopes
"Requested token in scopes {scopes:?} unavailable or expired, requesting new token."
);
let query_uri = format!(
@ -100,7 +99,7 @@ impl TokenProvider {
let response = request.await?;
let data = response.payload.first().ok_or(TokenError::Empty)?.to_vec();
let token = Token::from_json(String::from_utf8(data)?)?;
trace!("Got token: {:#?}", token);
trace!("Got token: {token:#?}");
self.lock(|inner| inner.tokens.push(token.clone()));
Ok(token)
}