atagen

matrix-rust-sdk

public
Star0
Watch0
ssh://brewery@pls.lobotomise.me:33/atagen/matrix-rust-sdk.git

Blame: crates/matrix-sdk-common/src/lib.rs

7ff8adafe9e4atagen2026-10-22 12:30 UTC1
// Copyright 2022 The Matrix.org Foundation C.I.C.
7ff8adafe9e4atagen2026-10-22 12:30 UTC2
//
7ff8adafe9e4atagen2026-10-22 12:30 UTC3
// Licensed under the Apache License, Version 2.0 (the "License");
7ff8adafe9e4atagen2026-10-22 12:30 UTC4
// you may not use this file except in compliance with the License.
7ff8adafe9e4atagen2026-10-22 12:30 UTC5
// You may obtain a copy of the License at
7ff8adafe9e4atagen2026-10-22 12:30 UTC6
//
7ff8adafe9e4atagen2026-10-22 12:30 UTC7
//     http://www.apache.org/licenses/LICENSE-2.0
7ff8adafe9e4atagen2026-10-22 12:30 UTC8
//
7ff8adafe9e4atagen2026-10-22 12:30 UTC9
// Unless required by applicable law or agreed to in writing, software
7ff8adafe9e4atagen2026-10-22 12:30 UTC10
// distributed under the License is distributed on an "AS IS" BASIS,
7ff8adafe9e4atagen2026-10-22 12:30 UTC11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7ff8adafe9e4atagen2026-10-22 12:30 UTC12
// See the License for the specific language governing permissions and
7ff8adafe9e4atagen2026-10-22 12:30 UTC13
// limitations under the License.
7ff8adafe9e4atagen2026-10-22 12:30 UTC14
7ff8adafe9e4atagen2026-10-22 12:30 UTC15
#![doc = include_str!("../README.md")]
7ff8adafe9e4atagen2026-10-22 12:30 UTC16
#![warn(missing_debug_implementations)]
7ff8adafe9e4atagen2026-10-22 12:30 UTC17
7ff8adafe9e4atagen2026-10-22 12:30 UTC18
use std::pin::Pin;
7ff8adafe9e4atagen2026-10-22 12:30 UTC19
7ff8adafe9e4atagen2026-10-22 12:30 UTC20
use ruma::{RoomVersionId, room_version_rules::RoomVersionRules};
7ff8adafe9e4atagen2026-10-22 12:30 UTC21
7ff8adafe9e4atagen2026-10-22 12:30 UTC22
#[cfg(test)]
7ff8adafe9e4atagen2026-10-22 12:30 UTC23
matrix_sdk_test_utils::init_tracing_for_tests!();
7ff8adafe9e4atagen2026-10-22 12:30 UTC24
7ff8adafe9e4atagen2026-10-22 12:30 UTC25
use futures_core::Future;
7ff8adafe9e4atagen2026-10-22 12:30 UTC26
#[doc(no_inline)]
7ff8adafe9e4atagen2026-10-22 12:30 UTC27
pub use ruma;
7ff8adafe9e4atagen2026-10-22 12:30 UTC28
7ff8adafe9e4atagen2026-10-22 12:30 UTC29
pub mod cross_process_lock;
7ff8adafe9e4atagen2026-10-22 12:30 UTC30
pub mod debug;
7ff8adafe9e4atagen2026-10-22 12:30 UTC31
pub mod deserialized_responses;
7ff8adafe9e4atagen2026-10-22 12:30 UTC32
mod edit_validation;
7ff8adafe9e4atagen2026-10-22 12:30 UTC33
pub mod executor;
7ff8adafe9e4atagen2026-10-22 12:30 UTC34
pub mod failures_cache;
7ff8adafe9e4atagen2026-10-22 12:30 UTC35
pub mod linked_chunk;
7ff8adafe9e4atagen2026-10-22 12:30 UTC36
pub mod locks;
7ff8adafe9e4atagen2026-10-22 12:30 UTC37
pub mod ring_buffer;
7ff8adafe9e4atagen2026-10-22 12:30 UTC38
pub mod serde_helpers;
7ff8adafe9e4atagen2026-10-22 12:30 UTC39
pub mod sleep;
7ff8adafe9e4atagen2026-10-22 12:30 UTC40
pub mod stream;
7ff8adafe9e4atagen2026-10-22 12:30 UTC41
pub mod task_monitor;
7ff8adafe9e4atagen2026-10-22 12:30 UTC42
pub mod timeout;
7ff8adafe9e4atagen2026-10-22 12:30 UTC43
pub mod tracing_timer;
7ff8adafe9e4atagen2026-10-22 12:30 UTC44
pub mod ttl;
7ff8adafe9e4atagen2026-10-22 12:30 UTC45
7ff8adafe9e4atagen2026-10-22 12:30 UTC46
// We cannot currently measure test coverage in the WASM environment, so
7ff8adafe9e4atagen2026-10-22 12:30 UTC47
// js_tracing is incorrectly flagged as untested. Disable coverage checking for
7ff8adafe9e4atagen2026-10-22 12:30 UTC48
// it.
7ff8adafe9e4atagen2026-10-22 12:30 UTC49
#[cfg(all(target_family = "wasm", not(tarpaulin_include)))]
7ff8adafe9e4atagen2026-10-22 12:30 UTC50
pub mod js_tracing;
7ff8adafe9e4atagen2026-10-22 12:30 UTC51
7ff8adafe9e4atagen2026-10-22 12:30 UTC52
pub use cross_process_lock::LEASE_DURATION_MS;
7ff8adafe9e4atagen2026-10-22 12:30 UTC53
pub use edit_validation::*;
7ff8adafe9e4atagen2026-10-22 12:30 UTC54
7ff8adafe9e4atagen2026-10-22 12:30 UTC55
/// Alias for `Send` on non-wasm, empty trait (implemented by everything) on
7ff8adafe9e4atagen2026-10-22 12:30 UTC56
/// wasm.
7ff8adafe9e4atagen2026-10-22 12:30 UTC57
#[cfg(not(target_family = "wasm"))]
7ff8adafe9e4atagen2026-10-22 12:30 UTC58
pub trait SendOutsideWasm: Send {}
7ff8adafe9e4atagen2026-10-22 12:30 UTC59
#[cfg(not(target_family = "wasm"))]
7ff8adafe9e4atagen2026-10-22 12:30 UTC60
impl<T: Send> SendOutsideWasm for T {}
7ff8adafe9e4atagen2026-10-22 12:30 UTC61
7ff8adafe9e4atagen2026-10-22 12:30 UTC62
/// Alias for `Send` on non-wasm, empty trait (implemented by everything) on
7ff8adafe9e4atagen2026-10-22 12:30 UTC63
/// wasm.
7ff8adafe9e4atagen2026-10-22 12:30 UTC64
#[cfg(target_family = "wasm")]
7ff8adafe9e4atagen2026-10-22 12:30 UTC65
pub trait SendOutsideWasm {}
7ff8adafe9e4atagen2026-10-22 12:30 UTC66
#[cfg(target_family = "wasm")]
7ff8adafe9e4atagen2026-10-22 12:30 UTC67
impl<T> SendOutsideWasm for T {}
7ff8adafe9e4atagen2026-10-22 12:30 UTC68
7ff8adafe9e4atagen2026-10-22 12:30 UTC69
/// Alias for `Sync` on non-wasm, empty trait (implemented by everything) on
7ff8adafe9e4atagen2026-10-22 12:30 UTC70
/// wasm.
7ff8adafe9e4atagen2026-10-22 12:30 UTC71
#[cfg(not(target_family = "wasm"))]
7ff8adafe9e4atagen2026-10-22 12:30 UTC72
pub trait SyncOutsideWasm: Sync {}
7ff8adafe9e4atagen2026-10-22 12:30 UTC73
#[cfg(not(target_family = "wasm"))]
7ff8adafe9e4atagen2026-10-22 12:30 UTC74
impl<T: Sync> SyncOutsideWasm for T {}
7ff8adafe9e4atagen2026-10-22 12:30 UTC75
7ff8adafe9e4atagen2026-10-22 12:30 UTC76
/// Alias for `Sync` on non-wasm, empty trait (implemented by everything) on
7ff8adafe9e4atagen2026-10-22 12:30 UTC77
/// wasm.
7ff8adafe9e4atagen2026-10-22 12:30 UTC78
#[cfg(target_family = "wasm")]
7ff8adafe9e4atagen2026-10-22 12:30 UTC79
pub trait SyncOutsideWasm {}
7ff8adafe9e4atagen2026-10-22 12:30 UTC80
#[cfg(target_family = "wasm")]
7ff8adafe9e4atagen2026-10-22 12:30 UTC81
impl<T> SyncOutsideWasm for T {}
7ff8adafe9e4atagen2026-10-22 12:30 UTC82
7ff8adafe9e4atagen2026-10-22 12:30 UTC83
/// Super trait that is used for our store traits, this trait will differ if
7ff8adafe9e4atagen2026-10-22 12:30 UTC84
/// it's used on WASM. WASM targets will not require `Send` and `Sync` to have
7ff8adafe9e4atagen2026-10-22 12:30 UTC85
/// implemented, while other targets will.
7ff8adafe9e4atagen2026-10-22 12:30 UTC86
pub trait AsyncTraitDeps: std::fmt::Debug + SendOutsideWasm + SyncOutsideWasm {}
7ff8adafe9e4atagen2026-10-22 12:30 UTC87
impl<T: std::fmt::Debug + SendOutsideWasm + SyncOutsideWasm> AsyncTraitDeps for T {}
7ff8adafe9e4atagen2026-10-22 12:30 UTC88
7ff8adafe9e4atagen2026-10-22 12:30 UTC89
// TODO: Remove in favor of impl Trait once allowed in associated types
7ff8adafe9e4atagen2026-10-22 12:30 UTC90
#[macro_export]
7ff8adafe9e4atagen2026-10-22 12:30 UTC91
macro_rules! boxed_into_future {
7ff8adafe9e4atagen2026-10-22 12:30 UTC92
    () => {
7ff8adafe9e4atagen2026-10-22 12:30 UTC93
        $crate::boxed_into_future!(extra_bounds: );
7ff8adafe9e4atagen2026-10-22 12:30 UTC94
    };
7ff8adafe9e4atagen2026-10-22 12:30 UTC95
    (extra_bounds: $($extra_bounds:tt)*) => {
7ff8adafe9e4atagen2026-10-22 12:30 UTC96
        #[cfg(target_family = "wasm")]
7ff8adafe9e4atagen2026-10-22 12:30 UTC97
        type IntoFuture = ::std::pin::Pin<::std::boxed::Box<
7ff8adafe9e4atagen2026-10-22 12:30 UTC98
            dyn ::std::future::Future<Output = Self::Output> + $($extra_bounds)*
7ff8adafe9e4atagen2026-10-22 12:30 UTC99
        >>;
7ff8adafe9e4atagen2026-10-22 12:30 UTC100
        #[cfg(not(target_family = "wasm"))]
7ff8adafe9e4atagen2026-10-22 12:30 UTC101
        type IntoFuture = ::std::pin::Pin<::std::boxed::Box<
7ff8adafe9e4atagen2026-10-22 12:30 UTC102
            dyn ::std::future::Future<Output = Self::Output> + Send + $($extra_bounds)*
7ff8adafe9e4atagen2026-10-22 12:30 UTC103
        >>;
7ff8adafe9e4atagen2026-10-22 12:30 UTC104
    };
7ff8adafe9e4atagen2026-10-22 12:30 UTC105
}
7ff8adafe9e4atagen2026-10-22 12:30 UTC106
7ff8adafe9e4atagen2026-10-22 12:30 UTC107
/// A `Box::pin` future that is `Send` on non-wasm, and without `Send` on wasm.
7ff8adafe9e4atagen2026-10-22 12:30 UTC108
#[cfg(target_family = "wasm")]
7ff8adafe9e4atagen2026-10-22 12:30 UTC109
pub type BoxFuture<'a, T> = Pin<Box<dyn Future<Output = T> + 'a>>;
7ff8adafe9e4atagen2026-10-22 12:30 UTC110
#[cfg(not(target_family = "wasm"))]
7ff8adafe9e4atagen2026-10-22 12:30 UTC111
pub type BoxFuture<'a, T> = Pin<Box<dyn Future<Output = T> + Send + 'a>>;
7ff8adafe9e4atagen2026-10-22 12:30 UTC112
7ff8adafe9e4atagen2026-10-22 12:30 UTC113
#[cfg(feature = "uniffi")]
7ff8adafe9e4atagen2026-10-22 12:30 UTC114
uniffi::setup_scaffolding!();
7ff8adafe9e4atagen2026-10-22 12:30 UTC115
7ff8adafe9e4atagen2026-10-22 12:30 UTC116
/// The room version to use as a fallback when the version of a room is unknown.
7ff8adafe9e4atagen2026-10-22 12:30 UTC117
pub const ROOM_VERSION_FALLBACK: RoomVersionId = RoomVersionId::V11;
7ff8adafe9e4atagen2026-10-22 12:30 UTC118
7ff8adafe9e4atagen2026-10-22 12:30 UTC119
/// The room version rules to use as a fallback when the version of a room is
7ff8adafe9e4atagen2026-10-22 12:30 UTC120
/// unknown or unsupported.
7ff8adafe9e4atagen2026-10-22 12:30 UTC121
///
7ff8adafe9e4atagen2026-10-22 12:30 UTC122
/// These are the rules of the [`ROOM_VERSION_FALLBACK`].
7ff8adafe9e4atagen2026-10-22 12:30 UTC123
pub const ROOM_VERSION_RULES_FALLBACK: RoomVersionRules = RoomVersionRules::V11;