sdk: Remove once_cell dependency

Use the types that were stabilized in the standard library instead.

Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
This commit is contained in:
Kévin Commaille
2026-02-20 15:23:11 +01:00
committed by Andy Balaam
parent aff26b1ed9
commit fc70a7da2c
8 changed files with 24 additions and 26 deletions

1
Cargo.lock generated
View File

@@ -3116,7 +3116,6 @@ dependencies = [
"mime",
"mime2ext",
"oauth2",
"once_cell",
"percent-encoding",
"pin-project-lite",
"proptest",

View File

@@ -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 }

View File

@@ -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<CrossProcessRefreshManager>,
cross_process_token_refresh_manager: OnceLock<CrossProcessRefreshManager>,
/// Deferred cross-process lock initializer.
///

View File

@@ -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<AbortOnDrop<()>>,
_task: OnceLock<AbortOnDrop<()>>,
/// 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,

View File

@@ -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<Raw<AnySyncTimelineEvent>> = Lazy::new(|| {
static MEMBER_EVENT: LazyLock<Raw<AnySyncTimelineEvent>> = LazyLock::new(|| {
EventFactory::new()
.member(user_id!("@example:localhost"))
.membership(MembershipState::Join)

View File

@@ -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(

View File

@@ -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<JsonValue> = Lazy::new(|| {
pub static PARENT_SPACE_SYNC: LazyLock<JsonValue> = LazyLock::new(|| {
json!({
"device_one_time_keys_count": {},
"next_batch": "s526_47314_0_7_1_1_1_11444_2",

View File

@@ -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<Mutex<(Option<Raw<AnyToDeviceEvent>>, Option<EncryptionInfo>)>>;
const WIDGET_ID: &str = "test-widget";
static ROOM_ID: Lazy<OwnedRoomId> = Lazy::new(|| owned_room_id!("!a98sd12bjh:example.org"));
static ROOM_ID: LazyLock<OwnedRoomId> = 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<JsonValue> = Lazy::new(|| {
static HELLO_EVENT: LazyLock<JsonValue> = LazyLock::new(|| {
json!({
"content": {
"body": "hello",
@@ -240,7 +244,7 @@ static HELLO_EVENT: Lazy<JsonValue> = Lazy::new(|| {
})
});
static TOMBSTONE_EVENT: Lazy<JsonValue> = Lazy::new(|| {
static TOMBSTONE_EVENT: LazyLock<JsonValue> = LazyLock::new(|| {
json!({
"content": {
"body": "This room has been replaced",