matrix_sdk_common/
lib.rs

1// Copyright 2022 The Matrix.org Foundation C.I.C.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#![doc = include_str!("../README.md")]
16#![warn(missing_debug_implementations)]
17
18use std::pin::Pin;
19
20use futures_core::Future;
21#[doc(no_inline)]
22pub use ruma;
23
24pub mod debug;
25pub mod deserialized_responses;
26pub mod executor;
27pub mod failures_cache;
28pub mod linked_chunk;
29pub mod locks;
30pub mod ring_buffer;
31pub mod serde_helpers;
32pub mod sleep;
33pub mod store_locks;
34pub mod stream;
35pub mod timeout;
36pub mod tracing_timer;
37pub mod ttl_cache;
38
39// We cannot currently measure test coverage in the WASM environment, so
40// js_tracing is incorrectly flagged as untested. Disable coverage checking for
41// it.
42#[cfg(all(target_family = "wasm", not(tarpaulin_include)))]
43pub mod js_tracing;
44
45pub use store_locks::LEASE_DURATION_MS;
46
47/// Alias for `Send` on non-wasm, empty trait (implemented by everything) on
48/// wasm.
49#[cfg(not(target_family = "wasm"))]
50pub trait SendOutsideWasm: Send {}
51#[cfg(not(target_family = "wasm"))]
52impl<T: Send> SendOutsideWasm for T {}
53
54/// Alias for `Send` on non-wasm, empty trait (implemented by everything) on
55/// wasm.
56#[cfg(target_family = "wasm")]
57pub trait SendOutsideWasm {}
58#[cfg(target_family = "wasm")]
59impl<T> SendOutsideWasm for T {}
60
61/// Alias for `Sync` on non-wasm, empty trait (implemented by everything) on
62/// wasm.
63#[cfg(not(target_family = "wasm"))]
64pub trait SyncOutsideWasm: Sync {}
65#[cfg(not(target_family = "wasm"))]
66impl<T: Sync> SyncOutsideWasm for T {}
67
68/// Alias for `Sync` on non-wasm, empty trait (implemented by everything) on
69/// wasm.
70#[cfg(target_family = "wasm")]
71pub trait SyncOutsideWasm {}
72#[cfg(target_family = "wasm")]
73impl<T> SyncOutsideWasm for T {}
74
75/// Super trait that is used for our store traits, this trait will differ if
76/// it's used on WASM. WASM targets will not require `Send` and `Sync` to have
77/// implemented, while other targets will.
78pub trait AsyncTraitDeps: std::fmt::Debug + SendOutsideWasm + SyncOutsideWasm {}
79impl<T: std::fmt::Debug + SendOutsideWasm + SyncOutsideWasm> AsyncTraitDeps for T {}
80
81// TODO: Remove in favor of impl Trait once allowed in associated types
82#[macro_export]
83macro_rules! boxed_into_future {
84    () => {
85        $crate::boxed_into_future!(extra_bounds: );
86    };
87    (extra_bounds: $($extra_bounds:tt)*) => {
88        #[cfg(target_family = "wasm")]
89        type IntoFuture = ::std::pin::Pin<::std::boxed::Box<
90            dyn ::std::future::Future<Output = Self::Output> + $($extra_bounds)*
91        >>;
92        #[cfg(not(target_family = "wasm"))]
93        type IntoFuture = ::std::pin::Pin<::std::boxed::Box<
94            dyn ::std::future::Future<Output = Self::Output> + Send + $($extra_bounds)*
95        >>;
96    };
97}
98
99/// A `Box::pin` future that is `Send` on non-wasm, and without `Send` on wasm.
100#[cfg(target_family = "wasm")]
101pub type BoxFuture<'a, T> = Pin<Box<dyn Future<Output = T> + 'a>>;
102#[cfg(not(target_family = "wasm"))]
103pub type BoxFuture<'a, T> = Pin<Box<dyn Future<Output = T> + Send + 'a>>;
104
105#[cfg(feature = "uniffi")]
106uniffi::setup_scaffolding!();