ruma/
lib.rs

1#![doc(html_favicon_url = "https://ruma.dev/favicon.ico")]
2#![doc(html_logo_url = "https://ruma.dev/images/logo.png")]
3//! Types and traits for working with the [Matrix](https://matrix.org) protocol.
4//!
5//! This crate re-exports things from all of the other ruma crates so you don't
6//! have to manually keep all the versions in sync.
7//!
8//! Which crates are re-exported can be configured through cargo features.
9//!
10//! > ⚠ Some details might be missing because rustdoc has trouble with re-exports so you may need
11//! > to refer to other crates' documentations.
12//!
13//! > 🛈 For internal consistency, Ruma uses American spelling for variable names. Names may differ
14//! > in the serialized representation, as the Matrix specification has a mix of British and
15//! > American English.
16//!
17//! # API features
18//!
19//! Depending on which parts of Matrix are relevant to you, activate the following features:
20//!
21//! * `appservice-api` -- Application Service API.
22//! * `client-api` -- Client-Server API.
23//! * `federation-api` -- Server-Server (Federation) API.
24//! * `identity-service-api` -- Identity Service API.
25//! * `push-gateway-api` -- Push Gateway API.
26//!
27//! These features have `client`- and `server`-optimized variants that are enabled respectively
28//! with the `-c` and `-s` suffixes. For example:
29//!   * `client-api-c` -- The Client-Server API optimized for the client side.
30//!   * `client-api-s` -- The Client-Server API optimized for the server side.
31//!
32//! # Compatibility features
33//!
34//! By default, the ruma crates are only able to handle strictly spec-compliant data and behaviour.
35//! However, due to the fact that Matrix is federated, that it is used by various implementations
36//! that might have different bugs, and that much of its data is immutable, they need to be able to
37//! interoperate with data that might differ slightly from the specification.
38//!
39//! This is the role of the `compat-*` cargo features. They allow the crates be more tolerant of
40//! external data and incoming requests for known and reasonable deviations from the spec, usually
41//! for historical reasons. They however do not permit the ruma crates to generate data that is not
42//! spec-compliant.
43//!
44//! Each cargo feature is documented briefly in the cargo manifest of the crate, and more thoroughly
45//! where the feature applies.
46//!
47//! # Convenience features
48//!
49//! These features are only useful if you want to use a method that requires it:
50//!
51//! * `rand` -- Generate random identifiers.
52//! * `markdown` -- Parse markdown to construct messages.
53//! * `html` -- Parse HTML to sanitize it or navigate its tree.
54//!   * `html-matrix` -- Enables the `matrix` feature of `ruma-html` to parse HTML elements data to
55//!     typed data as suggested by the Matrix Specification.
56//!
57//! # Unstable features
58//!
59//! By using these features, you opt out of all semver guarantees Ruma otherwise provides:
60//!
61//! * `unstable-mscXXXX`, where `XXXX` is the MSC number -- Upcoming Matrix features that may be
62//!   subject to change or removal.
63//! * `unstable-uniffi` -- Enables UniFFI bindings by adding conditional `uniffi` derives to _some_
64//!   types. This feature is currently a work in progress and, thus, unstable.
65//!
66//! # Common features
67//!
68//! These submodules are usually activated by the API features when needed:
69//!
70//! * `api`
71//! * `events`
72//! * `signatures`
73//!
74//! # Compile-time `cfg` settings
75//!
76//! These settings are accepted at compile time to configure the generated code. They can be set
77//! using the `RUSTFLAGS` environment variable like this:
78//!
79//! ```shell
80//! RUSTFLAGS="--cfg {key}=\"{value}\""
81//! ```
82//!
83//! or in `.cargo/config.toml`:
84//!
85//! ```toml
86//! # General setting for all targets, overridden by per-target `rustflags` setting if set.
87//! [build]
88//! rustflags = ["--cfg", "{key}=\"{value}\""]
89//!
90//! # Per-target setting.
91//! [target.<triple/cfg>]
92//! rustflags = ["--cfg", "{key}=\"{value}\""]
93//! ```
94//!
95//! They can also be configured using an environment variable at compile time, which has the benefit
96//! of not requiring to re-compile the whole dependency chain when their value is changed, like
97//! this:
98//!
99//! ```shell
100//! {UPPERCASE_KEY}="{value}"
101//! ```
102//!
103//! * `ruma_identifiers_storage` -- Choose the inner representation of the identifier types
104//!   generated with the `ruma_id` attribute macro. If the setting is not set or has an unknown
105//!   value, the owned identifiers use a `Box<str>` internally. The following values are also
106//!   supported:
107//!
108//!   * `Arc` -- Use an `Arc<str>`.
109//!
110//!   This setting can also be configured by setting the `RUMA_IDENTIFIERS_STORAGE` environment
111//!   variable.
112//! * `ruma_unstable_exhaustive_types` -- Most types in Ruma are marked as non-exhaustive to avoid
113//!   breaking changes when new fields are added in the specification. This setting compiles all
114//!   types as exhaustive. By enabling this feature you opt out of all semver guarantees Ruma
115//!   otherwise provides. This can also be configured by setting the
116//!   `RUMA_UNSTABLE_EXHAUSTIVE_TYPES` environment variable.
117
118#![warn(missing_docs)]
119#![cfg_attr(docsrs, feature(doc_cfg))]
120
121#[cfg(feature = "events")]
122#[doc(inline)]
123pub use ruma_events as events;
124#[cfg(feature = "html")]
125#[doc(inline)]
126pub use ruma_html as html;
127#[cfg(feature = "signatures")]
128#[doc(inline)]
129pub use ruma_signatures as signatures;
130#[cfg(feature = "state-res")]
131#[doc(inline)]
132pub use ruma_state_res as state_res;
133
134/// (De)serializable types for various [Matrix APIs][apis] requests and responses and abstractions
135/// for them.
136///
137/// [apis]: https://spec.matrix.org/latest/#matrix-apis
138#[cfg(feature = "api")]
139pub mod api {
140    #[cfg(any(feature = "appservice-api-c", feature = "appservice-api-s"))]
141    #[doc(inline)]
142    pub use ruma_appservice_api as appservice;
143    #[cfg(any(feature = "client-api-c", feature = "client-api-s"))]
144    #[doc(inline)]
145    pub use ruma_client_api as client;
146    // The metadata macro is `#[doc(hidden)]` by default to only show it in the `api` module
147    // instead of at the root of `ruma_common`, so we need to explicitly inline it where we
148    // want it.
149    #[doc(inline)]
150    pub use ruma_common::api::metadata;
151    pub use ruma_common::api::*;
152    #[cfg(any(feature = "federation-api-c", feature = "federation-api-s"))]
153    #[doc(inline)]
154    pub use ruma_federation_api as federation;
155    #[cfg(any(feature = "identity-service-api-c", feature = "identity-service-api-s"))]
156    #[doc(inline)]
157    pub use ruma_identity_service_api as identity_service;
158    #[cfg(any(feature = "push-gateway-api-c", feature = "push-gateway-api-s"))]
159    #[doc(inline)]
160    pub use ruma_push_gateway_api as push_gateway;
161}
162
163/// Canonical JSON types and related functions.
164pub mod canonical_json {
165    // The assert_to_canonical_json_eq macro is `#[doc(hidden)]` by default to only show it in the
166    // `canonical_json` module instead of at the root of `ruma_common`, so we need to explicitly
167    // inline it where we want it.
168    #[doc(inline)]
169    pub use ruma_common::canonical_json::assert_to_canonical_json_eq;
170    pub use ruma_common::canonical_json::*;
171}
172
173#[doc(no_inline)]
174pub use assign::assign;
175#[doc(no_inline)]
176pub use js_int::{Int, UInt, int, uint};
177#[doc(no_inline)]
178pub use js_option::JsOption;
179#[cfg(all(feature = "events", feature = "unstable-msc4334"))]
180#[doc(no_inline)]
181pub use language_tags::LanguageTag;
182pub use ruma_common::{CanonicalJsonError, CanonicalJsonObject, CanonicalJsonValue, *};
183pub use web_time as time;