atagen

matrix-rust-sdk

public
Star0
Watch0
ssh://brewery@pls.lobotomise.me:33/atagen/matrix-rust-sdk.git
crates/matrix-sdk-common/src/lib.rsRust123 lines4.1 KB
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
18
use std::pin::Pin;
19
20
use ruma::{RoomVersionId, room_version_rules::RoomVersionRules};
21
22
#[cfg(test)]
23
matrix_sdk_test_utils::init_tracing_for_tests!();
24
25
use futures_core::Future;
26
#[doc(no_inline)]
27
pub use ruma;
28
29
pub mod cross_process_lock;
30
pub mod debug;
31
pub mod deserialized_responses;
32
mod edit_validation;
33
pub mod executor;
34
pub mod failures_cache;
35
pub mod linked_chunk;
36
pub mod locks;
37
pub mod ring_buffer;
38
pub mod serde_helpers;
39
pub mod sleep;
40
pub mod stream;
41
pub mod task_monitor;
42
pub mod timeout;
43
pub mod tracing_timer;
44
pub mod ttl;
45
46
// We cannot currently measure test coverage in the WASM environment, so
47
// js_tracing is incorrectly flagged as untested. Disable coverage checking for
48
// it.
49
#[cfg(all(target_family = "wasm", not(tarpaulin_include)))]
50
pub mod js_tracing;
51
52
pub use cross_process_lock::LEASE_DURATION_MS;
53
pub use edit_validation::*;
54
55
/// Alias for `Send` on non-wasm, empty trait (implemented by everything) on
56
/// wasm.
57
#[cfg(not(target_family = "wasm"))]
58
pub trait SendOutsideWasm: Send {}
59
#[cfg(not(target_family = "wasm"))]
60
impl<T: Send> SendOutsideWasm for T {}
61
62
/// Alias for `Send` on non-wasm, empty trait (implemented by everything) on
63
/// wasm.
64
#[cfg(target_family = "wasm")]
65
pub trait SendOutsideWasm {}
66
#[cfg(target_family = "wasm")]
67
impl<T> SendOutsideWasm for T {}
68
69
/// Alias for `Sync` on non-wasm, empty trait (implemented by everything) on
70
/// wasm.
71
#[cfg(not(target_family = "wasm"))]
72
pub trait SyncOutsideWasm: Sync {}
73
#[cfg(not(target_family = "wasm"))]
74
impl<T: Sync> SyncOutsideWasm for T {}
75
76
/// Alias for `Sync` on non-wasm, empty trait (implemented by everything) on
77
/// wasm.
78
#[cfg(target_family = "wasm")]
79
pub trait SyncOutsideWasm {}
80
#[cfg(target_family = "wasm")]
81
impl<T> SyncOutsideWasm for T {}
82
83
/// Super trait that is used for our store traits, this trait will differ if
84
/// it's used on WASM. WASM targets will not require `Send` and `Sync` to have
85
/// implemented, while other targets will.
86
pub trait AsyncTraitDeps: std::fmt::Debug + SendOutsideWasm + SyncOutsideWasm {}
87
impl<T: std::fmt::Debug + SendOutsideWasm + SyncOutsideWasm> AsyncTraitDeps for T {}
88
89
// TODO: Remove in favor of impl Trait once allowed in associated types
90
#[macro_export]
91
macro_rules! boxed_into_future {
92
    () => {
93
        $crate::boxed_into_future!(extra_bounds: );
94
    };
95
    (extra_bounds: $($extra_bounds:tt)*) => {
96
        #[cfg(target_family = "wasm")]
97
        type IntoFuture = ::std::pin::Pin<::std::boxed::Box<
98
            dyn ::std::future::Future<Output = Self::Output> + $($extra_bounds)*
99
        >>;
100
        #[cfg(not(target_family = "wasm"))]
101
        type IntoFuture = ::std::pin::Pin<::std::boxed::Box<
102
            dyn ::std::future::Future<Output = Self::Output> + Send + $($extra_bounds)*
103
        >>;
104
    };
105
}
106
107
/// A `Box::pin` future that is `Send` on non-wasm, and without `Send` on wasm.
108
#[cfg(target_family = "wasm")]
109
pub type BoxFuture<'a, T> = Pin<Box<dyn Future<Output = T> + 'a>>;
110
#[cfg(not(target_family = "wasm"))]
111
pub type BoxFuture<'a, T> = Pin<Box<dyn Future<Output = T> + Send + 'a>>;
112
113
#[cfg(feature = "uniffi")]
114
uniffi::setup_scaffolding!();
115
116
/// The room version to use as a fallback when the version of a room is unknown.
117
pub const ROOM_VERSION_FALLBACK: RoomVersionId = RoomVersionId::V11;
118
119
/// The room version rules to use as a fallback when the version of a room is
120
/// unknown or unsupported.
121
///
122
/// These are the rules of the [`ROOM_VERSION_FALLBACK`].
123
pub const ROOM_VERSION_RULES_FALLBACK: RoomVersionRules = RoomVersionRules::V11;