From efebc94ecffee86d7ddaa2828c7c144be27341cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Commaille?= Date: Fri, 1 Nov 2024 15:39:26 +0100 Subject: [PATCH] chore: Remove once_cell dependency Use the types in std instead. Bumps the MSRV to 1.80. --- CONTRIBUTING.md | 2 +- Cargo.lock | 1 - Cargo.toml | 3 +-- src/components/action_button.rs | 6 ++--- src/components/avatar/editable.rs | 8 ++++--- src/components/avatar/image.rs | 6 ++--- src/components/crypto/identity_setup_view.rs | 8 ++++--- src/components/crypto/recovery_setup_view.rs | 5 +++-- src/components/pill/search_entry.rs | 5 ++--- src/components/rows/entry_add_row.rs | 6 ++--- src/components/rows/loading_button_row.rs | 7 +++--- src/components/rows/loading_row.rs | 7 +++--- src/components/rows/removable_row.rs | 7 +++--- src/components/rows/substring_entry_row.rs | 5 +++-- src/components/scale_revealer.rs | 10 +++++---- src/components/user_page.rs | 7 +++--- .../camera/camera_paintable/mod.rs | 5 +++-- src/contrib/qr_code_scanner/camera/mod.rs | 6 ++--- src/contrib/qr_code_scanner/mod.rs | 5 ++--- .../qr_code_scanner/qr_code_detector.rs | 22 +++++++++---------- src/login/session_setup_view.rs | 8 ++++--- src/main.rs | 8 ++++--- src/session/model/room/aliases.rs | 7 +++--- src/session/model/room/event/mod.rs | 6 ++--- src/session/model/room/join_rule.rs | 10 +++++---- src/session/model/room/mod.rs | 6 ++--- src/session/model/room/permissions.rs | 10 +++++---- src/session/model/room/timeline/mod.rs | 6 ++--- src/session/model/room_list/mod.rs | 7 +++--- .../verification/identity_verification.rs | 4 ++-- .../model/verification/verification_list.rs | 7 +++--- .../room_details/invite_subpage/list.rs | 4 ++-- .../permissions/add_members_subpage.rs | 7 +++--- .../view/content/room_history/item_row.rs | 9 ++++---- .../room_history/message_row/text/mod.rs | 5 +++-- .../message_toolbar/composer_state.rs | 7 +++--- src/session/view/sidebar/mod.rs | 8 ++++--- src/utils/media/image/queue.rs | 5 ++--- src/utils/mod.rs | 4 ++-- 39 files changed, 133 insertions(+), 126 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 73468590..18c4399e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -22,7 +22,7 @@ can also provide general help about using Rust in GNOME. ### Prerequisites -Fractal is written in Rust, so you will need to have at least Rust 1.76 and Cargo available on your +Fractal is written in Rust, so you will need to have at least Rust 1.80 and Cargo available on your system. You will also need to install the Rust nightly toolchain to be able to run our [pre-commit hook](#pre-commit), which can be done with: diff --git a/Cargo.lock b/Cargo.lock index 62f36b44..557f60c3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1373,7 +1373,6 @@ dependencies = [ "matrix-sdk-ui", "mime", "mime_guess", - "once_cell", "oo7", "pulldown-cmark", "qrcode", diff --git a/Cargo.toml b/Cargo.toml index 0559a19c..b6fda75a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ name = "fractal" version = "9.0.0" authors = ["Julian Sparber "] edition = "2021" -rust-version = "1.76" +rust-version = "1.80" publish = false [profile.release] @@ -31,7 +31,6 @@ indexmap = "2" linkify = "0.10.0" mime = "0.3" mime_guess = "2" -once_cell = "1" pulldown-cmark = "0.12" qrcode = "0.14" rand = "0.8" diff --git a/src/components/action_button.rs b/src/components/action_button.rs index 54952511..1c8eb296 100644 --- a/src/components/action_button.rs +++ b/src/components/action_button.rs @@ -33,10 +33,10 @@ mod imp { use std::{ cell::{Cell, RefCell}, marker::PhantomData, + sync::LazyLock, }; use glib::subclass::{InitializingObject, Signal}; - use once_cell::sync::Lazy; use super::*; @@ -89,8 +89,8 @@ mod imp { #[glib::derived_properties] impl ObjectImpl for ActionButton { fn signals() -> &'static [Signal] { - static SIGNALS: Lazy> = - Lazy::new(|| vec![Signal::builder("clicked").build()]); + static SIGNALS: LazyLock> = + LazyLock::new(|| vec![Signal::builder("clicked").build()]); SIGNALS.as_ref() } } diff --git a/src/components/avatar/editable.rs b/src/components/avatar/editable.rs index 2f879a5a..6b2b5016 100644 --- a/src/components/avatar/editable.rs +++ b/src/components/avatar/editable.rs @@ -38,10 +38,12 @@ pub enum EditableAvatarState { } mod imp { - use std::cell::{Cell, RefCell}; + use std::{ + cell::{Cell, RefCell}, + sync::LazyLock, + }; use glib::subclass::{InitializingObject, Signal}; - use once_cell::sync::Lazy; use super::*; @@ -120,7 +122,7 @@ mod imp { #[glib::derived_properties] impl ObjectImpl for EditableAvatar { fn signals() -> &'static [Signal] { - static SIGNALS: Lazy> = Lazy::new(|| { + static SIGNALS: LazyLock> = LazyLock::new(|| { vec![ Signal::builder("edit-avatar") .param_types([gio::File::static_type()]) diff --git a/src/components/avatar/image.rs b/src/components/avatar/image.rs index f5dc5c61..98746a5c 100644 --- a/src/components/avatar/image.rs +++ b/src/components/avatar/image.rs @@ -34,10 +34,10 @@ mod imp { use std::{ cell::{Cell, OnceCell, RefCell}, marker::PhantomData, + sync::LazyLock, }; use glib::subclass::Signal; - use once_cell::sync::Lazy; use super::*; @@ -78,8 +78,8 @@ mod imp { #[glib::derived_properties] impl ObjectImpl for AvatarImage { fn signals() -> &'static [Signal] { - static SIGNALS: Lazy> = - Lazy::new(|| vec![Signal::builder("error-changed").build()]); + static SIGNALS: LazyLock> = + LazyLock::new(|| vec![Signal::builder("error-changed").build()]); SIGNALS.as_ref() } } diff --git a/src/components/crypto/identity_setup_view.rs b/src/components/crypto/identity_setup_view.rs index 0c3b3fe4..3aa1830d 100644 --- a/src/components/crypto/identity_setup_view.rs +++ b/src/components/crypto/identity_setup_view.rs @@ -47,10 +47,12 @@ pub enum CryptoIdentitySetupNextStep { } mod imp { - use std::cell::{OnceCell, RefCell}; + use std::{ + cell::{OnceCell, RefCell}, + sync::LazyLock, + }; use glib::subclass::{InitializingObject, Signal}; - use once_cell::sync::Lazy; use super::*; @@ -102,7 +104,7 @@ mod imp { #[glib::derived_properties] impl ObjectImpl for CryptoIdentitySetupView { fn signals() -> &'static [Signal] { - static SIGNALS: Lazy> = Lazy::new(|| { + static SIGNALS: LazyLock> = LazyLock::new(|| { vec![ // The crypto identity setup is done. Signal::builder("completed") diff --git a/src/components/crypto/recovery_setup_view.rs b/src/components/crypto/recovery_setup_view.rs index f43116f9..f97094e2 100644 --- a/src/components/crypto/recovery_setup_view.rs +++ b/src/components/crypto/recovery_setup_view.rs @@ -44,8 +44,9 @@ pub enum CryptoRecoverySetupInitialPage { } mod imp { + use std::sync::LazyLock; + use glib::subclass::{InitializingObject, Signal}; - use once_cell::sync::Lazy; use super::*; @@ -111,7 +112,7 @@ mod imp { #[glib::derived_properties] impl ObjectImpl for CryptoRecoverySetupView { fn signals() -> &'static [Signal] { - static SIGNALS: Lazy> = Lazy::new(|| { + static SIGNALS: LazyLock> = LazyLock::new(|| { vec![ // Recovery is enabled. Signal::builder("completed").build(), diff --git a/src/components/pill/search_entry.rs b/src/components/pill/search_entry.rs index c3549ead..56d334dc 100644 --- a/src/components/pill/search_entry.rs +++ b/src/components/pill/search_entry.rs @@ -11,10 +11,9 @@ use crate::{ }; mod imp { - use std::{cell::RefCell, collections::HashMap, marker::PhantomData}; + use std::{cell::RefCell, collections::HashMap, marker::PhantomData, sync::LazyLock}; use glib::subclass::{InitializingObject, Signal}; - use once_cell::sync::Lazy; use super::*; @@ -56,7 +55,7 @@ mod imp { #[glib::derived_properties] impl ObjectImpl for PillSearchEntry { fn signals() -> &'static [Signal] { - static SIGNALS: Lazy> = Lazy::new(|| { + static SIGNALS: LazyLock> = LazyLock::new(|| { vec![Signal::builder("pill-removed") .param_types([PillSource::static_type()]) .build()] diff --git a/src/components/rows/entry_add_row.rs b/src/components/rows/entry_add_row.rs index 9404603a..bdcf09e7 100644 --- a/src/components/rows/entry_add_row.rs +++ b/src/components/rows/entry_add_row.rs @@ -4,10 +4,9 @@ use gtk::{glib, glib::closure_local, CompositeTemplate}; use crate::components::LoadingButton; mod imp { - use std::{cell::Cell, marker::PhantomData}; + use std::{cell::Cell, marker::PhantomData, sync::LazyLock}; use glib::subclass::{InitializingObject, Signal}; - use once_cell::sync::Lazy; use super::*; @@ -47,7 +46,8 @@ mod imp { #[glib::derived_properties] impl ObjectImpl for EntryAddRow { fn signals() -> &'static [Signal] { - static SIGNALS: Lazy> = Lazy::new(|| vec![Signal::builder("add").build()]); + static SIGNALS: LazyLock> = + LazyLock::new(|| vec![Signal::builder("add").build()]); SIGNALS.as_ref() } } diff --git a/src/components/rows/loading_button_row.rs b/src/components/rows/loading_button_row.rs index 5a72cc2a..a1054dda 100644 --- a/src/components/rows/loading_button_row.rs +++ b/src/components/rows/loading_button_row.rs @@ -9,10 +9,9 @@ use gtk::{ use crate::components::LoadingBin; mod imp { - use std::marker::PhantomData; + use std::{marker::PhantomData, sync::LazyLock}; use glib::subclass::{InitializingObject, Signal}; - use once_cell::sync::Lazy; use super::*; @@ -47,8 +46,8 @@ mod imp { #[glib::derived_properties] impl ObjectImpl for LoadingButtonRow { fn signals() -> &'static [Signal] { - static SIGNALS: Lazy> = - Lazy::new(|| vec![Signal::builder("activated").build()]); + static SIGNALS: LazyLock> = + LazyLock::new(|| vec![Signal::builder("activated").build()]); SIGNALS.as_ref() } diff --git a/src/components/rows/loading_row.rs b/src/components/rows/loading_row.rs index 3c72da1b..443e5355 100644 --- a/src/components/rows/loading_row.rs +++ b/src/components/rows/loading_row.rs @@ -10,10 +10,9 @@ use gtk::{ use crate::components::LoadingBin; mod imp { - use std::marker::PhantomData; + use std::{marker::PhantomData, sync::LazyLock}; use glib::subclass::InitializingObject; - use once_cell::sync::Lazy; use super::*; @@ -50,8 +49,8 @@ mod imp { #[glib::derived_properties] impl ObjectImpl for LoadingRow { fn signals() -> &'static [Signal] { - static SIGNALS: Lazy> = - Lazy::new(|| vec![Signal::builder("retry").build()]); + static SIGNALS: LazyLock> = + LazyLock::new(|| vec![Signal::builder("retry").build()]); SIGNALS.as_ref() } diff --git a/src/components/rows/removable_row.rs b/src/components/rows/removable_row.rs index bf2d5760..d4903b8a 100644 --- a/src/components/rows/removable_row.rs +++ b/src/components/rows/removable_row.rs @@ -4,10 +4,9 @@ use gtk::{glib, glib::closure_local, CompositeTemplate}; use crate::components::LoadingButton; mod imp { - use std::{cell::RefCell, marker::PhantomData}; + use std::{cell::RefCell, marker::PhantomData, sync::LazyLock}; use glib::subclass::{InitializingObject, Signal}; - use once_cell::sync::Lazy; use super::*; @@ -54,8 +53,8 @@ mod imp { #[glib::derived_properties] impl ObjectImpl for RemovableRow { fn signals() -> &'static [Signal] { - static SIGNALS: Lazy> = - Lazy::new(|| vec![Signal::builder("remove").build()]); + static SIGNALS: LazyLock> = + LazyLock::new(|| vec![Signal::builder("remove").build()]); SIGNALS.as_ref() } } diff --git a/src/components/rows/substring_entry_row.rs b/src/components/rows/substring_entry_row.rs index 844ac7ed..d7129b07 100644 --- a/src/components/rows/substring_entry_row.rs +++ b/src/components/rows/substring_entry_row.rs @@ -11,10 +11,10 @@ mod imp { use std::{ cell::{Cell, RefCell}, marker::PhantomData, + sync::LazyLock, }; use glib::subclass::{InitializingObject, Signal}; - use once_cell::sync::Lazy; use super::*; @@ -102,7 +102,8 @@ mod imp { impl ObjectImpl for SubstringEntryRow { fn signals() -> &'static [Signal] { - static SIGNALS: Lazy> = Lazy::new(|| vec![Signal::builder("add").build()]); + static SIGNALS: LazyLock> = + LazyLock::new(|| vec![Signal::builder("add").build()]); SIGNALS.as_ref() } diff --git a/src/components/scale_revealer.rs b/src/components/scale_revealer.rs index b004ed6c..06bd552b 100644 --- a/src/components/scale_revealer.rs +++ b/src/components/scale_revealer.rs @@ -5,10 +5,12 @@ use tracing::warn; const ANIMATION_DURATION: u32 = 250; mod imp { - use std::cell::{Cell, OnceCell, RefCell}; + use std::{ + cell::{Cell, OnceCell, RefCell}, + sync::LazyLock, + }; use glib::{clone, subclass::Signal}; - use once_cell::sync::Lazy; use super::*; @@ -35,8 +37,8 @@ mod imp { #[glib::derived_properties] impl ObjectImpl for ScaleRevealer { fn signals() -> &'static [Signal] { - static SIGNALS: Lazy> = - Lazy::new(|| vec![Signal::builder("transition-done").build()]); + static SIGNALS: LazyLock> = + LazyLock::new(|| vec![Signal::builder("transition-done").build()]); SIGNALS.as_ref() } diff --git a/src/components/user_page.rs b/src/components/user_page.rs index 95c84054..10baa3c5 100644 --- a/src/components/user_page.rs +++ b/src/components/user_page.rs @@ -23,10 +23,9 @@ use crate::{ }; mod imp { - use std::cell::RefCell; + use std::{cell::RefCell, sync::LazyLock}; use glib::subclass::{InitializingObject, Signal}; - use once_cell::sync::Lazy; use super::*; @@ -109,8 +108,8 @@ mod imp { #[glib::derived_properties] impl ObjectImpl for UserPage { fn signals() -> &'static [Signal] { - static SIGNALS: Lazy> = - Lazy::new(|| vec![Signal::builder("close").build()]); + static SIGNALS: LazyLock> = + LazyLock::new(|| vec![Signal::builder("close").build()]); SIGNALS.as_ref() } diff --git a/src/contrib/qr_code_scanner/camera/camera_paintable/mod.rs b/src/contrib/qr_code_scanner/camera/camera_paintable/mod.rs index 1b56d580..7c3de12d 100644 --- a/src/contrib/qr_code_scanner/camera/camera_paintable/mod.rs +++ b/src/contrib/qr_code_scanner/camera/camera_paintable/mod.rs @@ -12,8 +12,9 @@ pub enum Action { } mod imp { + use std::sync::LazyLock; + use glib::subclass::Signal; - use once_cell::sync::Lazy; use super::*; @@ -39,7 +40,7 @@ mod imp { impl ObjectImpl for CameraPaintable { fn signals() -> &'static [Signal] { - static SIGNALS: Lazy> = Lazy::new(|| { + static SIGNALS: LazyLock> = LazyLock::new(|| { vec![Signal::builder("code-detected") .param_types([QrVerificationDataBoxed::static_type()]) .run_first() diff --git a/src/contrib/qr_code_scanner/camera/mod.rs b/src/contrib/qr_code_scanner/camera/mod.rs index 65e6c15e..fcda29cb 100644 --- a/src/contrib/qr_code_scanner/camera/mod.rs +++ b/src/contrib/qr_code_scanner/camera/mod.rs @@ -1,8 +1,9 @@ //! Camera API. +use std::sync::LazyLock; + use futures_util::{future::LocalBoxFuture, FutureExt}; use gtk::{glib, prelude::*, subclass::prelude::*}; -use once_cell::sync::Lazy; use tracing::error; mod camera_paintable; @@ -13,7 +14,6 @@ pub use self::camera_paintable::Action; use self::camera_paintable::CameraPaintable; mod imp { - use super::*; #[repr(C)] @@ -74,7 +74,7 @@ impl Camera { impl Default for Camera { fn default() -> Self { - static CAMERA: Lazy = Lazy::new(Camera::new); + static CAMERA: LazyLock = LazyLock::new(Camera::new); CAMERA.to_owned() } diff --git a/src/contrib/qr_code_scanner/mod.rs b/src/contrib/qr_code_scanner/mod.rs index 650e8b74..94003b32 100644 --- a/src/contrib/qr_code_scanner/mod.rs +++ b/src/contrib/qr_code_scanner/mod.rs @@ -8,12 +8,11 @@ mod qr_code_detector; pub use camera::{Camera, CameraExt}; mod imp { - use std::cell::RefCell; + use std::{cell::RefCell, sync::LazyLock}; use adw::subclass::prelude::*; use glib::subclass::{InitializingObject, Signal}; use gtk::CompositeTemplate; - use once_cell::sync::Lazy; use super::*; @@ -43,7 +42,7 @@ mod imp { } impl ObjectImpl for QrCodeScanner { fn signals() -> &'static [Signal] { - static SIGNALS: Lazy> = Lazy::new(|| { + static SIGNALS: LazyLock> = LazyLock::new(|| { vec![Signal::builder("code-detected") .param_types([QrVerificationDataBoxed::static_type()]) .run_first() diff --git a/src/contrib/qr_code_scanner/qr_code_detector.rs b/src/contrib/qr_code_scanner/qr_code_detector.rs index edf4bc66..e272d0b7 100644 --- a/src/contrib/qr_code_scanner/qr_code_detector.rs +++ b/src/contrib/qr_code_scanner/qr_code_detector.rs @@ -11,11 +11,10 @@ use crate::contrib::qr_code_scanner::camera::Action; const HEADER: &[u8] = b"MATRIX"; mod imp { - use std::sync::Mutex; + use std::sync::{LazyLock, Mutex}; use gst::subclass::prelude::*; use gst_video::subclass::prelude::*; - use once_cell::sync::Lazy; use super::*; @@ -37,20 +36,21 @@ mod imp { impl GstObjectImpl for QrCodeDetector {} impl ElementImpl for QrCodeDetector { fn metadata() -> Option<&'static gst::subclass::ElementMetadata> { - static ELEMENT_METADATA: Lazy = Lazy::new(|| { - gst::subclass::ElementMetadata::new( - "Matrix Qr Code detector Sink", - "Sink/Video/QrCode/Matrix", - "A Qr code detector for Matrix", - "Julian Sparber ", - ) - }); + static ELEMENT_METADATA: LazyLock = + LazyLock::new(|| { + gst::subclass::ElementMetadata::new( + "Matrix Qr Code detector Sink", + "Sink/Video/QrCode/Matrix", + "A Qr code detector for Matrix", + "Julian Sparber ", + ) + }); Some(&*ELEMENT_METADATA) } fn pad_templates() -> &'static [gst::PadTemplate] { - static PAD_TEMPLATES: Lazy> = Lazy::new(|| { + static PAD_TEMPLATES: LazyLock> = LazyLock::new(|| { let caps = gst_video::video_make_raw_caps(&[gst_video::VideoFormat::Gray8]) .any_features() .build(); diff --git a/src/login/session_setup_view.rs b/src/login/session_setup_view.rs index 03b0bcc4..68d9a776 100644 --- a/src/login/session_setup_view.rs +++ b/src/login/session_setup_view.rs @@ -26,10 +26,12 @@ enum SessionSetupPage { } mod imp { - use std::cell::{OnceCell, RefCell}; + use std::{ + cell::{OnceCell, RefCell}, + sync::LazyLock, + }; use glib::subclass::{InitializingObject, Signal}; - use once_cell::sync::Lazy; use super::*; @@ -71,7 +73,7 @@ mod imp { #[glib::derived_properties] impl ObjectImpl for SessionSetupView { fn signals() -> &'static [Signal] { - static SIGNALS: Lazy> = Lazy::new(|| { + static SIGNALS: LazyLock> = LazyLock::new(|| { vec![ // The session setup is done. Signal::builder("completed").build(), diff --git a/src/main.rs b/src/main.rs index 90847960..e02f03ac 100644 --- a/src/main.rs +++ b/src/main.rs @@ -25,16 +25,18 @@ mod user_facing_error; mod utils; mod window; +use std::sync::LazyLock; + use gettextrs::*; use gtk::{gdk::Display, gio, IconTheme}; -use once_cell::sync::Lazy; use tracing_subscriber::{fmt, prelude::*, EnvFilter}; use self::{application::*, config::*, i18n::*, window::Window}; /// The default tokio runtime to be used for async tasks -pub static RUNTIME: Lazy = - Lazy::new(|| tokio::runtime::Runtime::new().unwrap()); +pub static RUNTIME: LazyLock = LazyLock::new(|| { + tokio::runtime::Runtime::new().expect("creating tokio runtime should succeed") +}); fn main() { // Initialize logger, debug is carried out via debug!, info!, warn! and error!. diff --git a/src/session/model/room/aliases.rs b/src/session/model/room/aliases.rs index adf4126c..03064387 100644 --- a/src/session/model/room/aliases.rs +++ b/src/session/model/room/aliases.rs @@ -14,10 +14,9 @@ use super::Room; use crate::spawn_tokio; mod imp { - use std::{cell::RefCell, marker::PhantomData}; + use std::{cell::RefCell, marker::PhantomData, sync::LazyLock}; use glib::subclass::Signal; - use once_cell::sync::Lazy; use super::*; @@ -53,8 +52,8 @@ mod imp { #[glib::derived_properties] impl ObjectImpl for RoomAliases { fn signals() -> &'static [Signal] { - static SIGNALS: Lazy> = - Lazy::new(|| vec![Signal::builder("changed").build()]); + static SIGNALS: LazyLock> = + LazyLock::new(|| vec![Signal::builder("changed").build()]); SIGNALS.as_ref() } } diff --git a/src/session/model/room/event/mod.rs b/src/session/model/room/event/mod.rs index 0362f7f1..ebe5f44d 100644 --- a/src/session/model/room/event/mod.rs +++ b/src/session/model/room/event/mod.rs @@ -112,10 +112,10 @@ mod imp { use std::{ cell::{Cell, OnceCell, RefCell}, marker::PhantomData, + sync::LazyLock, }; use glib::subclass::Signal; - use once_cell::sync::Lazy; use super::*; @@ -219,8 +219,8 @@ mod imp { #[glib::derived_properties] impl ObjectImpl for Event { fn signals() -> &'static [Signal] { - static SIGNALS: Lazy> = - Lazy::new(|| vec![Signal::builder("item-changed").build()]); + static SIGNALS: LazyLock> = + LazyLock::new(|| vec![Signal::builder("item-changed").build()]); SIGNALS.as_ref() } } diff --git a/src/session/model/room/join_rule.rs b/src/session/model/room/join_rule.rs index 62a26aca..79dd7cb5 100644 --- a/src/session/model/room/join_rule.rs +++ b/src/session/model/room/join_rule.rs @@ -52,10 +52,12 @@ impl From<&MatrixJoinRule> for JoinRuleValue { } mod imp { - use std::cell::{Cell, RefCell}; + use std::{ + cell::{Cell, RefCell}, + sync::LazyLock, + }; use glib::subclass::Signal; - use once_cell::sync::Lazy; use super::*; @@ -102,8 +104,8 @@ mod imp { #[glib::derived_properties] impl ObjectImpl for JoinRule { fn signals() -> &'static [Signal] { - static SIGNALS: Lazy> = - Lazy::new(|| vec![Signal::builder("changed").build()]); + static SIGNALS: LazyLock> = + LazyLock::new(|| vec![Signal::builder("changed").build()]); SIGNALS.as_ref() } diff --git a/src/session/model/room/mod.rs b/src/session/model/room/mod.rs index c7718462..62961caf 100644 --- a/src/session/model/room/mod.rs +++ b/src/session/model/room/mod.rs @@ -74,11 +74,11 @@ mod imp { cell::{Cell, OnceCell}, marker::PhantomData, ops::ControlFlow, + sync::LazyLock, time::SystemTime, }; use glib::subclass::Signal; - use once_cell::sync::Lazy; use super::*; @@ -232,8 +232,8 @@ mod imp { #[glib::derived_properties] impl ObjectImpl for Room { fn signals() -> &'static [Signal] { - static SIGNALS: Lazy> = - Lazy::new(|| vec![Signal::builder("room-forgotten").build()]); + static SIGNALS: LazyLock> = + LazyLock::new(|| vec![Signal::builder("room-forgotten").build()]); SIGNALS.as_ref() } } diff --git a/src/session/model/room/permissions.rs b/src/session/model/room/permissions.rs index 55b479e1..80c0ebc2 100644 --- a/src/session/model/room/permissions.rs +++ b/src/session/model/room/permissions.rs @@ -78,10 +78,12 @@ impl fmt::Display for MemberRole { } mod imp { - use std::cell::{Cell, OnceCell, RefCell}; + use std::{ + cell::{Cell, OnceCell, RefCell}, + sync::LazyLock, + }; use glib::subclass::Signal; - use once_cell::sync::Lazy; use ruma::events::room::power_levels::NotificationPowerLevelType; use super::*; @@ -167,8 +169,8 @@ mod imp { #[glib::derived_properties] impl ObjectImpl for Permissions { fn signals() -> &'static [Signal] { - static SIGNALS: Lazy> = - Lazy::new(|| vec![Signal::builder("changed").build()]); + static SIGNALS: LazyLock> = + LazyLock::new(|| vec![Signal::builder("changed").build()]); SIGNALS.as_ref() } } diff --git a/src/session/model/room/timeline/mod.rs b/src/session/model/room/timeline/mod.rs index 053f16a8..32d817ce 100644 --- a/src/session/model/room/timeline/mod.rs +++ b/src/session/model/room/timeline/mod.rs @@ -58,10 +58,10 @@ mod imp { use std::{ cell::{Cell, OnceCell, RefCell}, marker::PhantomData, + sync::LazyLock, }; use glib::subclass::Signal; - use once_cell::sync::Lazy; use super::*; @@ -136,8 +136,8 @@ mod imp { #[glib::derived_properties] impl ObjectImpl for Timeline { fn signals() -> &'static [Signal] { - static SIGNALS: Lazy> = - Lazy::new(|| vec![Signal::builder("read-change-trigger").build()]); + static SIGNALS: LazyLock> = + LazyLock::new(|| vec![Signal::builder("read-change-trigger").build()]); SIGNALS.as_ref() } diff --git a/src/session/model/room_list/mod.rs b/src/session/model/room_list/mod.rs index a6b590b5..b5da2e63 100644 --- a/src/session/model/room_list/mod.rs +++ b/src/session/model/room_list/mod.rs @@ -26,10 +26,9 @@ use crate::{ }; mod imp { - use std::cell::RefCell; + use std::{cell::RefCell, sync::LazyLock}; use glib::subclass::Signal; - use once_cell::sync::Lazy; use super::*; @@ -64,8 +63,8 @@ mod imp { #[glib::derived_properties] impl ObjectImpl for RoomList { fn signals() -> &'static [Signal] { - static SIGNALS: Lazy> = - Lazy::new(|| vec![Signal::builder("pending-rooms-changed").build()]); + static SIGNALS: LazyLock> = + LazyLock::new(|| vec![Signal::builder("pending-rooms-changed").build()]); SIGNALS.as_ref() } diff --git a/src/session/model/verification/identity_verification.rs b/src/session/model/verification/identity_verification.rs index 8935b21f..362e98ab 100644 --- a/src/session/model/verification/identity_verification.rs +++ b/src/session/model/verification/identity_verification.rs @@ -120,10 +120,10 @@ mod imp { use std::{ cell::{Cell, OnceCell, RefCell}, marker::PhantomData, + sync::LazyLock, }; use glib::subclass::Signal; - use once_cell::sync::Lazy; use super::*; @@ -188,7 +188,7 @@ mod imp { #[glib::derived_properties] impl ObjectImpl for IdentityVerification { fn signals() -> &'static [Signal] { - static SIGNALS: Lazy> = Lazy::new(|| { + static SIGNALS: LazyLock> = LazyLock::new(|| { vec![ // The SAS data changed. Signal::builder("sas-data-changed").build(), diff --git a/src/session/model/verification/verification_list.rs b/src/session/model/verification/verification_list.rs index 42cf20cc..ab590ae7 100644 --- a/src/session/model/verification/verification_list.rs +++ b/src/session/model/verification/verification_list.rs @@ -18,11 +18,10 @@ use crate::{ }; mod imp { - use std::cell::RefCell; + use std::{cell::RefCell, sync::LazyLock}; use glib::subclass::Signal; use indexmap::IndexMap; - use once_cell::sync::Lazy; use super::*; @@ -46,8 +45,8 @@ mod imp { #[glib::derived_properties] impl ObjectImpl for VerificationList { fn signals() -> &'static [Signal] { - static SIGNALS: Lazy> = - Lazy::new(|| vec![Signal::builder("secret-received").build()]); + static SIGNALS: LazyLock> = + LazyLock::new(|| vec![Signal::builder("secret-received").build()]); SIGNALS.as_ref() } } diff --git a/src/session/view/content/room_details/invite_subpage/list.rs b/src/session/view/content/room_details/invite_subpage/list.rs index 6344ade4..9f8b8417 100644 --- a/src/session/view/content/room_details/invite_subpage/list.rs +++ b/src/session/view/content/room_details/invite_subpage/list.rs @@ -34,10 +34,10 @@ mod imp { cell::{Cell, OnceCell, RefCell}, collections::HashMap, marker::PhantomData, + sync::LazyLock, }; use glib::subclass::Signal; - use once_cell::sync::Lazy; use super::*; @@ -71,7 +71,7 @@ mod imp { #[glib::derived_properties] impl ObjectImpl for InviteList { fn signals() -> &'static [Signal] { - static SIGNALS: Lazy> = Lazy::new(|| { + static SIGNALS: LazyLock> = LazyLock::new(|| { vec![ Signal::builder("invitee-added") .param_types([InviteItem::static_type()]) diff --git a/src/session/view/content/room_details/permissions/add_members_subpage.rs b/src/session/view/content/room_details/permissions/add_members_subpage.rs index 6275b31b..332938c1 100644 --- a/src/session/view/content/room_details/permissions/add_members_subpage.rs +++ b/src/session/view/content/room_details/permissions/add_members_subpage.rs @@ -16,10 +16,9 @@ use crate::{ }; mod imp { - use std::{cell::RefCell, collections::HashMap}; + use std::{cell::RefCell, collections::HashMap, sync::LazyLock}; use glib::subclass::{InitializingObject, Signal}; - use once_cell::sync::Lazy; use super::*; @@ -70,8 +69,8 @@ mod imp { #[glib::derived_properties] impl ObjectImpl for PermissionsAddMembersSubpage { fn signals() -> &'static [Signal] { - static SIGNALS: Lazy> = - Lazy::new(|| vec![Signal::builder("selection-changed").build()]); + static SIGNALS: LazyLock> = + LazyLock::new(|| vec![Signal::builder("selection-changed").build()]); SIGNALS.as_ref() } diff --git a/src/session/view/content/room_history/item_row.rs b/src/session/view/content/room_history/item_row.rs index 19fef663..94ad40f1 100644 --- a/src/session/view/content/room_history/item_row.rs +++ b/src/session/view/content/room_history/item_row.rs @@ -1,8 +1,9 @@ +use std::sync::LazyLock; + use adw::{prelude::*, subclass::prelude::*}; use gettextrs::gettext; use gtk::{gio, glib, glib::clone}; use matrix_sdk_ui::timeline::TimelineItemContent; -use once_cell::sync::Lazy; use ruma::events::room::message::MessageType; use tracing::error; @@ -975,7 +976,7 @@ unsafe impl Sync for MenuModelSendSync {} /// The `MenuModel` for common message event actions, including reactions. fn event_message_menu_model_with_reactions() -> &'static gio::MenuModel { - static MODEL: Lazy = Lazy::new(|| { + static MODEL: LazyLock = LazyLock::new(|| { MenuModelSendSync( gtk::Builder::from_resource( "/org/gnome/Fractal/ui/session/view/content/room_history/event_actions.ui", @@ -989,7 +990,7 @@ fn event_message_menu_model_with_reactions() -> &'static gio::MenuModel { /// The `MenuModel` for common message event actions, without reactions. fn event_message_menu_model_no_reactions() -> &'static gio::MenuModel { - static MODEL: Lazy = Lazy::new(|| { + static MODEL: LazyLock = LazyLock::new(|| { MenuModelSendSync( gtk::Builder::from_resource( "/org/gnome/Fractal/ui/session/view/content/room_history/event_actions.ui", @@ -1003,7 +1004,7 @@ fn event_message_menu_model_no_reactions() -> &'static gio::MenuModel { /// The `MenuModel` for common state event actions. fn event_state_menu_model() -> &'static gio::MenuModel { - static MODEL: Lazy = Lazy::new(|| { + static MODEL: LazyLock = LazyLock::new(|| { MenuModelSendSync( gtk::Builder::from_resource( "/org/gnome/Fractal/ui/session/view/content/room_history/event_actions.ui", diff --git a/src/session/view/content/room_history/message_row/text/mod.rs b/src/session/view/content/room_history/message_row/text/mod.rs index 65cd0ffe..a5cf100a 100644 --- a/src/session/view/content/room_history/message_row/text/mod.rs +++ b/src/session/view/content/room_history/message_row/text/mod.rs @@ -1,7 +1,8 @@ +use std::sync::LazyLock; + use adw::{prelude::BinExt, subclass::prelude::*}; use gtk::{glib, glib::clone, pango, prelude::*}; use matrix_sdk::ruma::events::room::message::FormattedBody; -use once_cell::sync::Lazy; use ruma::{ events::room::message::MessageFormat, html::{Html, ListBehavior, SanitizerConfig}, @@ -433,7 +434,7 @@ const SUPPORTED_BLOCK_ELEMENTS: &[&str] = &[ ]; /// HTML sanitizer config for HTML messages. -static HTML_MESSAGE_SANITIZER_CONFIG: Lazy = Lazy::new(|| { +static HTML_MESSAGE_SANITIZER_CONFIG: LazyLock = LazyLock::new(|| { SanitizerConfig::compat() .allow_elements( SUPPORTED_INLINE_ELEMENTS diff --git a/src/session/view/content/room_history/message_toolbar/composer_state.rs b/src/session/view/content/room_history/message_toolbar/composer_state.rs index bd2e441b..650ea0dd 100644 --- a/src/session/view/content/room_history/message_toolbar/composer_state.rs +++ b/src/session/view/content/room_history/message_toolbar/composer_state.rs @@ -30,11 +30,10 @@ const MENTION_START_TAG: &str = ""; const MENTION_END_TAG: &str = ""; mod imp { - use std::{cell::RefCell, marker::PhantomData}; + use std::{cell::RefCell, marker::PhantomData, sync::LazyLock}; use futures_util::lock::Mutex; use glib::subclass::Signal; - use once_cell::sync::Lazy; use super::*; @@ -76,8 +75,8 @@ mod imp { #[glib::derived_properties] impl ObjectImpl for ComposerState { fn signals() -> &'static [Signal] { - static SIGNALS: Lazy> = - Lazy::new(|| vec![Signal::builder("related-to-changed").build()]); + static SIGNALS: LazyLock> = + LazyLock::new(|| vec![Signal::builder("related-to-changed").build()]); SIGNALS.as_ref() } diff --git a/src/session/view/sidebar/mod.rs b/src/session/view/sidebar/mod.rs index 4ac0bdd0..23eea111 100644 --- a/src/session/view/sidebar/mod.rs +++ b/src/session/view/sidebar/mod.rs @@ -29,10 +29,12 @@ use crate::{ }; mod imp { - use std::cell::{Cell, OnceCell, RefCell}; + use std::{ + cell::{Cell, OnceCell, RefCell}, + sync::LazyLock, + }; use glib::subclass::{InitializingObject, Signal}; - use once_cell::sync::Lazy; use super::*; @@ -94,7 +96,7 @@ mod imp { #[glib::derived_properties] impl ObjectImpl for Sidebar { fn signals() -> &'static [Signal] { - static SIGNALS: Lazy> = Lazy::new(|| { + static SIGNALS: LazyLock> = LazyLock::new(|| { vec![ Signal::builder("drop-source-category-changed").build(), Signal::builder("drop-active-target-category-changed").build(), diff --git a/src/utils/media/image/queue.rs b/src/utils/media/image/queue.rs index c6bd708a..22204205 100644 --- a/src/utils/media/image/queue.rs +++ b/src/utils/media/image/queue.rs @@ -3,7 +3,7 @@ use std::{ fmt, future::IntoFuture, path::PathBuf, - sync::{Arc, Mutex}, + sync::{Arc, LazyLock, Mutex}, time::{Duration, Instant}, }; @@ -13,7 +13,6 @@ use matrix_sdk::{ media::{MediaRequest, UniqueKey}, Client, }; -use once_cell::sync::Lazy; use tokio::{ sync::{broadcast, Mutex as AsyncMutex}, task::{spawn_blocking, AbortHandle}, @@ -27,7 +26,7 @@ use crate::{ }; /// The default image request queue. -pub static IMAGE_QUEUE: Lazy = Lazy::new(ImageRequestQueue::new); +pub static IMAGE_QUEUE: LazyLock = LazyLock::new(ImageRequestQueue::new); /// The default limit of the [`ImageRequestQueue`], aka the maximum number of /// concurrent image requests. diff --git a/src/utils/mod.rs b/src/utils/mod.rs index 06f8a7e5..5aec7075 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -19,6 +19,7 @@ use std::{ fmt, path::PathBuf, rc::{Rc, Weak}, + sync::LazyLock, }; use futures_util::{ @@ -26,7 +27,6 @@ use futures_util::{ pin_mut, }; use gtk::{gdk, gio, glib, prelude::*, subclass::prelude::*}; -use once_cell::sync::Lazy; use regex::Regex; pub use self::{ @@ -98,7 +98,7 @@ pub fn freplace(s: String, args: &[(&str, &str)]) -> String { } /// Regex that matches a string that only includes emojis. -pub static EMOJI_REGEX: Lazy = Lazy::new(|| { +pub static EMOJI_REGEX: LazyLock = LazyLock::new(|| { Regex::new( r"(?x) ^