From ef7bfec946e3ec50a777b92b167d9257e12bccca Mon Sep 17 00:00:00 2001
From: Kubat <maelle.martin@proton.me>
Date: Thu, 5 Dec 2024 11:32:47 +0100
Subject: [PATCH] MISC: Run cargo update & fix clippy warnings

---
 Cargo.lock                             | 58 +++++++++++++-------------
 amadeus/src/app/bottom_bar.rs          |  2 +-
 amadeus/src/config.rs                  |  2 +-
 amadeus/src/store.rs                   |  2 +-
 amadeus/src/store/history.rs           |  2 +-
 amadeus/src/store/playlist_content.rs  |  2 +-
 amadeus/src/store/queue_level.rs       |  2 +-
 lektor_utils/src/config/serde_utils.rs |  2 +-
 lektord/src/c_wrapper/commands.rs      | 19 +++++----
 lektord/src/c_wrapper/mod.rs           | 41 +++++++++---------
 10 files changed, 70 insertions(+), 62 deletions(-)

diff --git a/Cargo.lock b/Cargo.lock
index 0245213b..bb565208 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -230,9 +230,9 @@ checksum = "55cc3b69f167a1ef2e161439aa98aed94e6028e5f9a59be9a6ffb47aef1651f9"
 
 [[package]]
 name = "anyhow"
-version = "1.0.93"
+version = "1.0.94"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "4c95c10ba0b00a02636238b814946408b1322d5ac4760326e6fb8ec956d85775"
+checksum = "c1fd03a028ef38ba2276dce7e33fcd6369c158a1bca17946c4b1b701891c1ff7"
 
 [[package]]
 name = "apply"
@@ -892,9 +892,9 @@ dependencies = [
 
 [[package]]
 name = "clap"
-version = "4.5.21"
+version = "4.5.22"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "fb3b4b9e5a7c7514dfa52869339ee98b3156b0bfb4e8a77c4ff4babb64b1604f"
+checksum = "69371e34337c4c984bbe322360c2547210bf632eb2814bbe78a6e87a2935bd2b"
 dependencies = [
  "clap_builder",
  "clap_derive",
@@ -902,9 +902,9 @@ dependencies = [
 
 [[package]]
 name = "clap_builder"
-version = "4.5.21"
+version = "4.5.22"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b17a95aa67cc7b5ebd32aa5370189aa0d79069ef1c64ce893bd30fb24bff20ec"
+checksum = "6e24c1b4099818523236a8ca881d2b45db98dadfb4625cf6608c12069fcbbde1"
 dependencies = [
  "anstyle",
  "clap_lex",
@@ -1156,7 +1156,7 @@ dependencies = [
 [[package]]
 name = "cosmic-config"
 version = "0.1.0"
-source = "git+https://github.com/pop-os/libcosmic.git#b524ccb0a46b1ca585db09638c33e39e79829716"
+source = "git+https://github.com/pop-os/libcosmic.git#ff0ba4860c9ba732e601485f1952fde5fe5f6952"
 dependencies = [
  "atomicwrites",
  "cosmic-config-derive",
@@ -1178,7 +1178,7 @@ dependencies = [
 [[package]]
 name = "cosmic-config-derive"
 version = "0.1.0"
-source = "git+https://github.com/pop-os/libcosmic.git#b524ccb0a46b1ca585db09638c33e39e79829716"
+source = "git+https://github.com/pop-os/libcosmic.git#ff0ba4860c9ba732e601485f1952fde5fe5f6952"
 dependencies = [
  "quote",
  "syn 1.0.109",
@@ -1201,7 +1201,7 @@ dependencies = [
 [[package]]
 name = "cosmic-settings-daemon"
 version = "0.1.0"
-source = "git+https://github.com/pop-os/dbus-settings-bindings#62100129240d164e39fff16bda34faad520936de"
+source = "git+https://github.com/pop-os/dbus-settings-bindings#0eee63a96c8b1f6555ca797b5c12545c372b1a1b"
 dependencies = [
  "zbus 4.4.0",
 ]
@@ -1232,7 +1232,7 @@ dependencies = [
 [[package]]
 name = "cosmic-theme"
 version = "0.1.0"
-source = "git+https://github.com/pop-os/libcosmic.git#b524ccb0a46b1ca585db09638c33e39e79829716"
+source = "git+https://github.com/pop-os/libcosmic.git#ff0ba4860c9ba732e601485f1952fde5fe5f6952"
 dependencies = [
  "almost",
  "cosmic-config",
@@ -2327,9 +2327,9 @@ checksum = "dfa686283ad6dd069f105e5ab091b04c62850d3e4cf5d67debad1933f55023df"
 
 [[package]]
 name = "http"
-version = "1.1.0"
+version = "1.2.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258"
+checksum = "f16ca2af56261c99fba8bac40a10251ce8188205a4c448fbb745a2e4daa76fea"
 dependencies = [
  "bytes",
  "fnv",
@@ -2525,7 +2525,7 @@ dependencies = [
 [[package]]
 name = "iced"
 version = "0.14.0-dev"
-source = "git+https://github.com/pop-os/libcosmic.git#b524ccb0a46b1ca585db09638c33e39e79829716"
+source = "git+https://github.com/pop-os/libcosmic.git#ff0ba4860c9ba732e601485f1952fde5fe5f6952"
 dependencies = [
  "dnd",
  "iced_accessibility",
@@ -2543,7 +2543,7 @@ dependencies = [
 [[package]]
 name = "iced_accessibility"
 version = "0.1.0"
-source = "git+https://github.com/pop-os/libcosmic.git#b524ccb0a46b1ca585db09638c33e39e79829716"
+source = "git+https://github.com/pop-os/libcosmic.git#ff0ba4860c9ba732e601485f1952fde5fe5f6952"
 dependencies = [
  "accesskit",
  "accesskit_winit",
@@ -2552,7 +2552,7 @@ dependencies = [
 [[package]]
 name = "iced_core"
 version = "0.14.0-dev"
-source = "git+https://github.com/pop-os/libcosmic.git#b524ccb0a46b1ca585db09638c33e39e79829716"
+source = "git+https://github.com/pop-os/libcosmic.git#ff0ba4860c9ba732e601485f1952fde5fe5f6952"
 dependencies = [
  "bitflags 2.6.0",
  "bytes",
@@ -2575,7 +2575,7 @@ dependencies = [
 [[package]]
 name = "iced_futures"
 version = "0.14.0-dev"
-source = "git+https://github.com/pop-os/libcosmic.git#b524ccb0a46b1ca585db09638c33e39e79829716"
+source = "git+https://github.com/pop-os/libcosmic.git#ff0ba4860c9ba732e601485f1952fde5fe5f6952"
 dependencies = [
  "futures",
  "iced_core",
@@ -2601,7 +2601,7 @@ dependencies = [
 [[package]]
 name = "iced_graphics"
 version = "0.14.0-dev"
-source = "git+https://github.com/pop-os/libcosmic.git#b524ccb0a46b1ca585db09638c33e39e79829716"
+source = "git+https://github.com/pop-os/libcosmic.git#ff0ba4860c9ba732e601485f1952fde5fe5f6952"
 dependencies = [
  "bitflags 2.6.0",
  "bytemuck",
@@ -2623,7 +2623,7 @@ dependencies = [
 [[package]]
 name = "iced_renderer"
 version = "0.14.0-dev"
-source = "git+https://github.com/pop-os/libcosmic.git#b524ccb0a46b1ca585db09638c33e39e79829716"
+source = "git+https://github.com/pop-os/libcosmic.git#ff0ba4860c9ba732e601485f1952fde5fe5f6952"
 dependencies = [
  "iced_graphics",
  "iced_tiny_skia",
@@ -2635,7 +2635,7 @@ dependencies = [
 [[package]]
 name = "iced_runtime"
 version = "0.14.0-dev"
-source = "git+https://github.com/pop-os/libcosmic.git#b524ccb0a46b1ca585db09638c33e39e79829716"
+source = "git+https://github.com/pop-os/libcosmic.git#ff0ba4860c9ba732e601485f1952fde5fe5f6952"
 dependencies = [
  "bytes",
  "dnd",
@@ -2649,7 +2649,7 @@ dependencies = [
 [[package]]
 name = "iced_tiny_skia"
 version = "0.14.0-dev"
-source = "git+https://github.com/pop-os/libcosmic.git#b524ccb0a46b1ca585db09638c33e39e79829716"
+source = "git+https://github.com/pop-os/libcosmic.git#ff0ba4860c9ba732e601485f1952fde5fe5f6952"
 dependencies = [
  "bytemuck",
  "cosmic-text",
@@ -2665,7 +2665,7 @@ dependencies = [
 [[package]]
 name = "iced_wgpu"
 version = "0.14.0-dev"
-source = "git+https://github.com/pop-os/libcosmic.git#b524ccb0a46b1ca585db09638c33e39e79829716"
+source = "git+https://github.com/pop-os/libcosmic.git#ff0ba4860c9ba732e601485f1952fde5fe5f6952"
 dependencies = [
  "as-raw-xcb-connection",
  "bitflags 2.6.0",
@@ -2696,7 +2696,7 @@ dependencies = [
 [[package]]
 name = "iced_widget"
 version = "0.14.0-dev"
-source = "git+https://github.com/pop-os/libcosmic.git#b524ccb0a46b1ca585db09638c33e39e79829716"
+source = "git+https://github.com/pop-os/libcosmic.git#ff0ba4860c9ba732e601485f1952fde5fe5f6952"
 dependencies = [
  "dnd",
  "iced_renderer",
@@ -2713,7 +2713,7 @@ dependencies = [
 [[package]]
 name = "iced_winit"
 version = "0.14.0-dev"
-source = "git+https://github.com/pop-os/libcosmic.git#b524ccb0a46b1ca585db09638c33e39e79829716"
+source = "git+https://github.com/pop-os/libcosmic.git#ff0ba4860c9ba732e601485f1952fde5fe5f6952"
 dependencies = [
  "dnd",
  "iced_futures",
@@ -2979,9 +2979,9 @@ dependencies = [
 
 [[package]]
 name = "io-lifetimes"
-version = "2.0.3"
+version = "2.0.4"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "5a611371471e98973dbcab4e0ec66c31a10bc356eeb4d54a0e05eac8158fe38c"
+checksum = "06432fb54d3be7964ecd3649233cddf80db2832f47fec34c01f65b3d9d774983"
 
 [[package]]
 name = "ipnet"
@@ -3312,7 +3312,7 @@ checksum = "09d6582e104315a817dff97f75133544b2e094ee22447d2acf4a74e189ba06fc"
 [[package]]
 name = "libcosmic"
 version = "0.1.0"
-source = "git+https://github.com/pop-os/libcosmic.git#b524ccb0a46b1ca585db09638c33e39e79829716"
+source = "git+https://github.com/pop-os/libcosmic.git#ff0ba4860c9ba732e601485f1952fde5fe5f6952"
 dependencies = [
  "apply",
  "ashpd 0.9.2",
@@ -5651,9 +5651,9 @@ dependencies = [
 
 [[package]]
 name = "tokio-util"
-version = "0.7.12"
+version = "0.7.13"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a"
+checksum = "d7fcaa8d55a2bdd6b83ace262b016eca0d79ee02818c5c1bcdf0305114081078"
 dependencies = [
  "bytes",
  "futures-core",
@@ -6212,7 +6212,7 @@ checksum = "c89532cc712a2adb119eb4d09694b402576052254d0bb284f82ac1c47fb786ad"
 dependencies = [
  "bitflags 2.6.0",
  "downcast-rs",
- "io-lifetimes 2.0.3",
+ "io-lifetimes 2.0.4",
  "rustix 0.38.41",
  "wayland-backend",
  "wayland-scanner",
diff --git a/amadeus/src/app/bottom_bar.rs b/amadeus/src/app/bottom_bar.rs
index 6f12b2e1..4fd33230 100644
--- a/amadeus/src/app/bottom_bar.rs
+++ b/amadeus/src/app/bottom_bar.rs
@@ -121,7 +121,7 @@ fn view_kara_id<'a>(kid: KId) -> Element<'a, Message> {
 /// kara is playing.
 pub fn view<'a>(app: &AppModel) -> Element<'a, Message> {
     match app.lektord_state.current_kid() {
-        None => return widget::row().into(),
+        None => widget::row().into(),
         Some(kid) => match app.store.get(kid) {
             KaraOrId::Kara(kara) => vec![view_left_part(kara), view_right_part(kara)],
             KaraOrId::Id(kid) => vec![view_kara_id(kid)],
diff --git a/amadeus/src/config.rs b/amadeus/src/config.rs
index 24e21a14..4c79d76e 100644
--- a/amadeus/src/config.rs
+++ b/amadeus/src/config.rs
@@ -128,7 +128,7 @@ impl From<&log::Level> for LogLevel {
 impl<'de> Deserialize<'de> for LogLevel {
     fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
         struct StrVisitor;
-        impl<'de> Visitor<'de> for StrVisitor {
+        impl Visitor<'_> for StrVisitor {
             type Value = log::Level;
 
             fn expecting(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
diff --git a/amadeus/src/store.rs b/amadeus/src/store.rs
index ff6f2297..92656b99 100644
--- a/amadeus/src/store.rs
+++ b/amadeus/src/store.rs
@@ -18,7 +18,7 @@ pub enum KaraOrId<'a> {
     Id(KId),
 }
 
-impl<'a> KaraOrId<'a> {
+impl KaraOrId<'_> {
     pub fn id(&self) -> KId {
         match self {
             KaraOrId::Kara(kara) => kara.id,
diff --git a/amadeus/src/store/history.rs b/amadeus/src/store/history.rs
index eae05c48..447a1309 100644
--- a/amadeus/src/store/history.rs
+++ b/amadeus/src/store/history.rs
@@ -19,7 +19,7 @@ impl<'a> HistoryIter<'a> {
     }
 }
 
-impl<'a> Iterator for HistoryIter<'a> {
+impl Iterator for HistoryIter<'_> {
     type Item = KId;
 
     fn next(&mut self) -> Option<Self::Item> {
diff --git a/amadeus/src/store/playlist_content.rs b/amadeus/src/store/playlist_content.rs
index 1b6c7a20..ec5512e0 100644
--- a/amadeus/src/store/playlist_content.rs
+++ b/amadeus/src/store/playlist_content.rs
@@ -18,7 +18,7 @@ impl<'a> PlaylistContentIter<'a> {
     }
 }
 
-impl<'a> Iterator for PlaylistContentIter<'a> {
+impl Iterator for PlaylistContentIter<'_> {
     type Item = KId;
 
     fn next(&mut self) -> Option<Self::Item> {
diff --git a/amadeus/src/store/queue_level.rs b/amadeus/src/store/queue_level.rs
index c90f9952..a83f4738 100644
--- a/amadeus/src/store/queue_level.rs
+++ b/amadeus/src/store/queue_level.rs
@@ -19,7 +19,7 @@ impl<'a> QueueLevelIter<'a> {
     }
 }
 
-impl<'a> Iterator for QueueLevelIter<'a> {
+impl Iterator for QueueLevelIter<'_> {
     type Item = KId;
 
     fn next(&mut self) -> Option<Self::Item> {
diff --git a/lektor_utils/src/config/serde_utils.rs b/lektor_utils/src/config/serde_utils.rs
index 09a6fb9a..52a82993 100644
--- a/lektor_utils/src/config/serde_utils.rs
+++ b/lektor_utils/src/config/serde_utils.rs
@@ -30,7 +30,7 @@ pub fn deserialize_log_level<'de, D: Deserializer<'de>>(
         };
     }
 
-    impl<'de> Visitor<'de> for LogLevelVisitor {
+    impl Visitor<'_> for LogLevelVisitor {
         type Value = LogLevel;
 
         fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
diff --git a/lektord/src/c_wrapper/commands.rs b/lektord/src/c_wrapper/commands.rs
index c12fe75a..d2294e7b 100644
--- a/lektord/src/c_wrapper/commands.rs
+++ b/lektord/src/c_wrapper/commands.rs
@@ -104,13 +104,18 @@ pub(crate) fn player_set_playback_volume(vol: i64) -> Result<()> {
 }
 
 fn send_msg(msg: PlayerEvent) {
-    match unsafe { STATE.get() } {
-        Some((sender, _)) => {
-            let _ = sender
-                .blocking_send(msg)
-                .map_err(|err| log::error!("failed to send msg {msg:?}: {err}"));
-        }
-        None => log::error!("no lektord state was set for the player module"),
+    match (STATE.read().ok())
+        .and_then(|lock| {
+            lock.get().map(|(sender, _)| {
+                sender
+                    .blocking_send(msg)
+                    .with_context(|| format!("failed to send message: {msg:?}"))
+            })
+        })
+        .context("no lektord state was set for the player module, or failed to lock its mutex")
+    {
+        Ok(Err(err)) | Err(err) => log::error!("{err}"),
+        Ok(Ok(())) => {}
     }
 }
 
diff --git a/lektord/src/c_wrapper/mod.rs b/lektord/src/c_wrapper/mod.rs
index 97b4d3c7..d744f2a6 100644
--- a/lektord/src/c_wrapper/mod.rs
+++ b/lektord/src/c_wrapper/mod.rs
@@ -1,12 +1,12 @@
 //! Interface with the C/C++ part of the code. The only place we allow unsafe code in this crate.
 
 use crate::LektorStatePtr;
-use anyhow::{bail, ensure, Context, Result};
+use anyhow::{ensure, Context as _, Result};
 use lektor_utils::config::LektorPlayerConfig;
 use std::{
     ffi::*,
     ptr::NonNull,
-    sync::{Arc, OnceLock},
+    sync::{Arc, OnceLock, RwLock},
 };
 
 mod abort;
@@ -21,10 +21,12 @@ pub(crate) use commands::*;
 /// constructor...
 ///
 /// TODO: Pass it to the player module and see how to decrement the strong count latter...
-static mut STATE: OnceLock<(
-    tokio::sync::mpsc::Sender<PlayerEvent>,
-    tokio::task::JoinHandle<()>,
-)> = OnceLock::new();
+static STATE: RwLock<
+    OnceLock<(
+        tokio::sync::mpsc::Sender<PlayerEvent>,
+        tokio::task::JoinHandle<()>,
+    )>,
+> = RwLock::new(OnceLock::new());
 
 #[derive(Debug, Clone, Copy)]
 enum PlayerEvent {
@@ -112,13 +114,15 @@ pub(crate) fn init_player_module(ptr: LektorStatePtr, config: LektorPlayerConfig
         }
     });
 
-    unsafe {
-        // Set the state for the C/C++ code
-        ensure!(
-            STATE.set((sender, handle)).is_ok(),
-            "failed to register the lektord state pointer for the player module"
-        );
+    // Set the state for the C/C++ code
+    ensure!(
+        (STATE.write().ok().context("failed to lock state mutex")?)
+            .set((sender, handle))
+            .is_ok(),
+        "failed to register the lektord state pointer for the player module"
+    );
 
+    unsafe {
         // Pass options to the C/C++ code
         ensure!(
             0 == mod_set_msg_options(
@@ -155,13 +159,12 @@ pub async fn close_player_module() -> Result<()> {
         fn mod_close() -> c_int;
     }
 
-    match unsafe { STATE.take() } {
-        None => bail!("the player state wasn't initialized"),
-        Some((sender, handle)) => {
-            drop(sender);
-            let _ = handle.await.map_err(|e| log::error!("{e}"));
-        }
-    }
+    let (sender, handle) = (STATE.write().ok().context("failed to lock state mutex")?)
+        .take()
+        .context("the player state wasn't initialized")?;
+
+    drop(sender);
+    let _ = handle.await.map_err(|e| log::error!("{e}"));
 
     (0 == unsafe { mod_close() })
         .then_some(())
-- 
GitLab