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 sleep;
32pub mod store_locks;
33pub mod timeout;
34pub mod tracing_timer;
35pub mod ttl_cache;
36
37// We cannot currently measure test coverage in the WASM environment, so
38// js_tracing is incorrectly flagged as untested. Disable coverage checking for
39// it.
40#[cfg(all(target_arch = "wasm32", not(tarpaulin_include)))]
41pub mod js_tracing;
42
43pub use store_locks::LEASE_DURATION_MS;
44
45/// Alias for `Send` on non-wasm, empty trait (implemented by everything) on
46/// wasm.
47#[cfg(not(target_arch = "wasm32"))]
48pub trait SendOutsideWasm: Send {}
49#[cfg(not(target_arch = "wasm32"))]
50impl<T: Send> SendOutsideWasm for T {}
51
52/// Alias for `Send` on non-wasm, empty trait (implemented by everything) on
53/// wasm.
54#[cfg(target_arch = "wasm32")]
55pub trait SendOutsideWasm {}
56#[cfg(target_arch = "wasm32")]
57impl<T> SendOutsideWasm for T {}
58
59/// Alias for `Sync` on non-wasm, empty trait (implemented by everything) on
60/// wasm.
61#[cfg(not(target_arch = "wasm32"))]
62pub trait SyncOutsideWasm: Sync {}
63#[cfg(not(target_arch = "wasm32"))]
64impl<T: Sync> SyncOutsideWasm for T {}
65
66/// Alias for `Sync` on non-wasm, empty trait (implemented by everything) on
67/// wasm.
68#[cfg(target_arch = "wasm32")]
69pub trait SyncOutsideWasm {}
70#[cfg(target_arch = "wasm32")]
71impl<T> SyncOutsideWasm for T {}
72
73/// Super trait that is used for our store traits, this trait will differ if
74/// it's used on WASM. WASM targets will not require `Send` and `Sync` to have
75/// implemented, while other targets will.
76pub trait AsyncTraitDeps: std::fmt::Debug + SendOutsideWasm + SyncOutsideWasm {}
77impl<T: std::fmt::Debug + SendOutsideWasm + SyncOutsideWasm> AsyncTraitDeps for T {}
78
79// TODO: Remove in favor of impl Trait once allowed in associated types
80#[macro_export]
81macro_rules! boxed_into_future {
82    () => {
83        $crate::boxed_into_future!(extra_bounds: );
84    };
85    (extra_bounds: $($extra_bounds:tt)*) => {
86        #[cfg(target_arch = "wasm32")]
87        type IntoFuture = ::std::pin::Pin<::std::boxed::Box<
88            dyn ::std::future::Future<Output = Self::Output> + $($extra_bounds)*
89        >>;
90        #[cfg(not(target_arch = "wasm32"))]
91        type IntoFuture = ::std::pin::Pin<::std::boxed::Box<
92            dyn ::std::future::Future<Output = Self::Output> + Send + $($extra_bounds)*
93        >>;
94    };
95}
96
97/// A `Box::pin` future that is `Send` on non-wasm, and without `Send` on wasm.
98#[cfg(target_arch = "wasm32")]
99pub type BoxFuture<'a, T> = Pin<Box<dyn Future<Output = T> + 'a>>;
100#[cfg(not(target_arch = "wasm32"))]
101pub type BoxFuture<'a, T> = Pin<Box<dyn Future<Output = T> + Send + 'a>>;
102
103#[cfg(feature = "uniffi")]
104uniffi::setup_scaffolding!();