From fc70a7da2cd6be9c25488f8548abf4d59c8fc115 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Commaille?= Date: Fri, 20 Feb 2026 15:23:11 +0100 Subject: [PATCH] sdk: Remove once_cell dependency MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use the types that were stabilized in the standard library instead. Signed-off-by: Kévin Commaille --- Cargo.lock | 1 - crates/matrix-sdk/Cargo.toml | 1 - crates/matrix-sdk/src/authentication/oauth/mod.rs | 6 +++--- .../matrix-sdk/src/client/thread_subscriptions.rs | 7 +++---- crates/matrix-sdk/src/event_handler/mod.rs | 5 ++--- crates/matrix-sdk/src/paginators/room.rs | 7 +++---- crates/matrix-sdk/tests/integration/room/spaces.rs | 9 ++++----- crates/matrix-sdk/tests/integration/widget.rs | 14 +++++++++----- 8 files changed, 24 insertions(+), 26 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 59bb86586..420334b6c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3116,7 +3116,6 @@ dependencies = [ "mime", "mime2ext", "oauth2", - "once_cell", "percent-encoding", "pin-project-lite", "proptest", diff --git a/crates/matrix-sdk/Cargo.toml b/crates/matrix-sdk/Cargo.toml index 5973e1e05..343b8f0ff 100644 --- a/crates/matrix-sdk/Cargo.toml +++ b/crates/matrix-sdk/Cargo.toml @@ -118,7 +118,6 @@ matrix-sdk-test = { workspace = true, optional = true } mime.workspace = true mime2ext = "0.1.54" oauth2.workspace = true -once_cell.workspace = true percent-encoding = "2.3.2" pin-project-lite.workspace = true rand = { workspace = true, optional = true } diff --git a/crates/matrix-sdk/src/authentication/oauth/mod.rs b/crates/matrix-sdk/src/authentication/oauth/mod.rs index 5d934e428..efed6e6c4 100644 --- a/crates/matrix-sdk/src/authentication/oauth/mod.rs +++ b/crates/matrix-sdk/src/authentication/oauth/mod.rs @@ -160,6 +160,8 @@ //! [`ErrorKind::UnknownToken`]: ruma::api::client::error::ErrorKind::UnknownToken //! [`examples/oauth_cli`]: https://github.com/matrix-org/matrix-rust-sdk/tree/main/examples/oauth_cli +#[cfg(feature = "e2e-encryption")] +use std::sync::OnceLock; #[cfg(feature = "e2e-encryption")] use std::time::Duration; use std::{ @@ -178,8 +180,6 @@ use error::{ }; #[cfg(feature = "e2e-encryption")] use matrix_sdk_base::crypto::types::qr_login::QrCodeData; -#[cfg(feature = "e2e-encryption")] -use matrix_sdk_base::once_cell::sync::OnceCell; use matrix_sdk_base::{SessionMeta, store::RoomLoadSettings}; #[cfg(feature = "e2e-encryption")] use matrix_sdk_common::cross_process_lock::CrossProcessLockConfig; @@ -237,7 +237,7 @@ use crate::{Client, HttpError, RefreshTokenError, Result, client::SessionChange, pub(crate) struct OAuthCtx { /// Lock and state when multiple processes may refresh an OAuth 2.0 session. #[cfg(feature = "e2e-encryption")] - cross_process_token_refresh_manager: OnceCell, + cross_process_token_refresh_manager: OnceLock, /// Deferred cross-process lock initializer. /// diff --git a/crates/matrix-sdk/src/client/thread_subscriptions.rs b/crates/matrix-sdk/src/client/thread_subscriptions.rs index fc359da8e..4e785881d 100644 --- a/crates/matrix-sdk/src/client/thread_subscriptions.rs +++ b/crates/matrix-sdk/src/client/thread_subscriptions.rs @@ -15,7 +15,7 @@ use std::{ collections::BTreeMap, sync::{ - Arc, + Arc, OnceLock, atomic::{self, AtomicBool}, }, }; @@ -26,7 +26,6 @@ use matrix_sdk_base::{ store::{StoredThreadSubscription, ThreadSubscriptionStatus}, }; use matrix_sdk_common::executor::spawn; -use once_cell::sync::OnceCell; use ruma::{ EventId, OwnedEventId, OwnedRoomId, RoomId, api::client::threads::get_thread_subscriptions_changes::unstable::{ @@ -114,7 +113,7 @@ impl GuardedStoreAccess { pub struct ThreadSubscriptionCatchup { /// The task catching up thread subscriptions in the background. - _task: OnceCell>, + _task: OnceLock>, /// Whether the known list of thread subscriptions is outdated or not, i.e. /// all thread subscriptions have been caught up @@ -143,7 +142,7 @@ impl ThreadSubscriptionCatchup { let uniq_mutex = Arc::new(Mutex::new(())); let this = Arc::new(Self { - _task: OnceCell::new(), + _task: OnceLock::new(), is_outdated, client: weak_client, ping_sender, diff --git a/crates/matrix-sdk/src/event_handler/mod.rs b/crates/matrix-sdk/src/event_handler/mod.rs index 9c9c7ecb5..74debf5b0 100644 --- a/crates/matrix-sdk/src/event_handler/mod.rs +++ b/crates/matrix-sdk/src/event_handler/mod.rs @@ -737,7 +737,7 @@ mod tests { use std::{ future, sync::{ - Arc, + Arc, LazyLock, atomic::{AtomicU8, Ordering::SeqCst}, }, }; @@ -745,7 +745,6 @@ mod tests { use assert_matches2::assert_let; use matrix_sdk_common::{deserialized_responses::EncryptionInfo, locks::Mutex}; use matrix_sdk_test::SyncResponseBuilder; - use once_cell::sync::Lazy; use ruma::{ event_id, events::{ @@ -773,7 +772,7 @@ mod tests { test_utils::{logged_in_client, no_retry_test_client}, }; - static MEMBER_EVENT: Lazy> = Lazy::new(|| { + static MEMBER_EVENT: LazyLock> = LazyLock::new(|| { EventFactory::new() .member(user_id!("@example:localhost")) .membership(MembershipState::Join) diff --git a/crates/matrix-sdk/src/paginators/room.rs b/crates/matrix-sdk/src/paginators/room.rs index 7146dc374..64a3e6060 100644 --- a/crates/matrix-sdk/src/paginators/room.rs +++ b/crates/matrix-sdk/src/paginators/room.rs @@ -416,14 +416,13 @@ impl PaginableRoom for Room { #[cfg(all(not(target_family = "wasm"), test))] mod tests { - use std::sync::Arc; + use std::sync::{Arc, LazyLock}; use assert_matches2::assert_let; use futures_core::Future; use futures_util::FutureExt as _; use matrix_sdk_base::deserialized_responses::TimelineEvent; use matrix_sdk_test::{async_test, event_factory::EventFactory}; - use once_cell::sync::Lazy; use ruma::{EventId, RoomId, UInt, UserId, api::Direction, event_id, room_id, uint, user_id}; use tokio::{ spawn, @@ -475,8 +474,8 @@ mod tests { } } - static ROOM_ID: Lazy<&RoomId> = Lazy::new(|| room_id!("!dune:herbert.org")); - static USER_ID: Lazy<&UserId> = Lazy::new(|| user_id!("@paul:atreid.es")); + static ROOM_ID: LazyLock<&RoomId> = LazyLock::new(|| room_id!("!dune:herbert.org")); + static USER_ID: LazyLock<&UserId> = LazyLock::new(|| user_id!("@paul:atreid.es")); impl PaginableRoom for TestRoom { async fn event_with_context( diff --git a/crates/matrix-sdk/tests/integration/room/spaces.rs b/crates/matrix-sdk/tests/integration/room/spaces.rs index 870718416..e2fd7998f 100644 --- a/crates/matrix-sdk/tests/integration/room/spaces.rs +++ b/crates/matrix-sdk/tests/integration/room/spaces.rs @@ -1,10 +1,9 @@ -use std::time::Duration; +use std::{sync::LazyLock, time::Duration}; use assert_matches2::assert_let; use futures_util::StreamExt; use matrix_sdk::{Client, config::SyncSettings, room::ParentSpace}; use matrix_sdk_test::{DEFAULT_TEST_ROOM_ID, async_test, test_json}; -use once_cell::sync::Lazy; use ruma::{RoomId, room_id}; use serde_json::{Value as JsonValue, json}; use wiremock::{ @@ -14,10 +13,10 @@ use wiremock::{ use crate::{MockServer, logged_in_client_with_server, mock_sync}; -pub static DEFAULT_TEST_SPACE_ID: Lazy<&RoomId> = - Lazy::new(|| room_id!("!hIMjEx205EXNyjVPCV:localhost")); +pub static DEFAULT_TEST_SPACE_ID: LazyLock<&RoomId> = + LazyLock::new(|| room_id!("!hIMjEx205EXNyjVPCV:localhost")); -pub static PARENT_SPACE_SYNC: Lazy = Lazy::new(|| { +pub static PARENT_SPACE_SYNC: LazyLock = LazyLock::new(|| { json!({ "device_one_time_keys_count": {}, "next_batch": "s526_47314_0_7_1_1_1_11444_2", diff --git a/crates/matrix-sdk/tests/integration/widget.rs b/crates/matrix-sdk/tests/integration/widget.rs index ddcc38868..938ab2248 100644 --- a/crates/matrix-sdk/tests/integration/widget.rs +++ b/crates/matrix-sdk/tests/integration/widget.rs @@ -12,7 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. -use std::{future, pin::pin, sync::Arc, time::Duration}; +use std::{ + future, + pin::pin, + sync::{Arc, LazyLock}, + time::Duration, +}; use assert_matches::assert_matches; use assert_matches2::assert_let; @@ -31,7 +36,6 @@ use matrix_sdk_common::{ deserialized_responses::EncryptionInfo, executor::spawn, locks::Mutex, timeout::timeout, }; use matrix_sdk_test::{ALICE, BOB, JoinedRoomBuilder, async_test, event_factory::EventFactory}; -use once_cell::sync::Lazy; use ruma::{ OwnedRoomId, api::client::to_device::send_event_to_device::v3::Messages, @@ -64,7 +68,7 @@ macro_rules! json_string { type HandledDeviceEventMutex = Arc>, Option)>>; const WIDGET_ID: &str = "test-widget"; -static ROOM_ID: Lazy = Lazy::new(|| owned_room_id!("!a98sd12bjh:example.org")); +static ROOM_ID: LazyLock = LazyLock::new(|| owned_room_id!("!a98sd12bjh:example.org")); struct DummyCapabilitiesProvider; @@ -226,7 +230,7 @@ async fn test_negotiate_capabilities_immediately() { assert_matches!(driver_handle.recv().now_or_never(), None); } -static HELLO_EVENT: Lazy = Lazy::new(|| { +static HELLO_EVENT: LazyLock = LazyLock::new(|| { json!({ "content": { "body": "hello", @@ -240,7 +244,7 @@ static HELLO_EVENT: Lazy = Lazy::new(|| { }) }); -static TOMBSTONE_EVENT: Lazy = Lazy::new(|| { +static TOMBSTONE_EVENT: LazyLock = LazyLock::new(|| { json!({ "content": { "body": "This room has been replaced",