Skip to content

Commit 64a3487

Browse files
committed
feat(common): Implement BackingStore for all Arc<T> where T: BackingStore.
This patch implements `BackingStore` for all `Arc<T>` where `T: BackingStore`.
1 parent 877d665 commit 64a3487

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

crates/matrix-sdk-common/src/store_locks.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
4040
use std::{
4141
error::Error,
42+
ops::Deref,
4243
sync::{
4344
atomic::{self, AtomicU32},
4445
Arc,
@@ -51,7 +52,7 @@ use tracing::{debug, error, info, instrument, trace};
5152

5253
use crate::{
5354
executor::{spawn, JoinHandle},
54-
SendOutsideWasm,
55+
SendOutsideWasm, SyncOutsideWasm,
5556
};
5657

5758
/// A lock generation is an integer incremented each time it is taken by another
@@ -76,6 +77,24 @@ pub trait BackingStore {
7677
) -> Result<bool, Self::LockError>;
7778
}
7879

80+
#[cfg_attr(target_arch = "wasm32", async_trait::async_trait(?Send))]
81+
#[cfg_attr(not(target_arch = "wasm32"), async_trait::async_trait)]
82+
impl<T> BackingStore for Arc<T>
83+
where
84+
T: BackingStore + SendOutsideWasm + SyncOutsideWasm,
85+
{
86+
type LockError = T::LockError;
87+
88+
async fn try_lock(
89+
&self,
90+
lease_duration_ms: u32,
91+
key: &str,
92+
holder: &str,
93+
) -> Result<bool, Self::LockError> {
94+
self.deref().try_lock(lease_duration_ms, key, holder).await
95+
}
96+
}
97+
7998
/// Small state machine to handle wait times.
8099
#[derive(Clone, Debug)]
81100
enum WaitingTime {

0 commit comments

Comments
 (0)