If the homeserver provides a state event to a client, it means that it considers the event to be valid. If a state event is valid, it always updates the state map of the room. So ignoring events that fail to deserialize means that the local state map is different than the one from the server. In some cases the Matrix spec even explicitly says that if a required field is missing from the content of a state event, it should be treated as if the event is missing from the state map. And if a required field is missing, the event will fail to deserialize. So this handles state events very closely to how a server would we only deserialize the event type and the state key first to make sure that a valid state event always updates the local state map. Then we only deserialize the events lazily when we encounter an event type that updates the `RoomInfo`. Because we deserialize the event lazily and some methods might edit parts of an event before passing it to `RoomInfo`, the (possibly edited) deserialized event is cached alongside the raw event and its keys to be able to pass it further down the chain. Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
Matrix Rust SDK
The Matrix Rust SDK is a collection of libraries that make it easier to build Matrix clients in Rust.
Development of the SDK is proudly sponsored and maintained by Element. Element uses the SDK in their next-generation mobile apps Element X on iOS and Android and has plans to introduce it to the web and desktop clients as well.
The SDK is also the basis for multiple Matrix projects and we welcome contributions from all.
Purpose
The SDK takes care of the low-level details like encryption, syncing, and room state, so you can focus on your app's logic and UI. Whether you're writing a small bot, a desktop client, or something in between, the SDK is designed to be flexible, async-friendly, and ready to use out of the box.
Project structure
The Matrix Rust SDK is made up of several crates that build on top of each other. The following crates are expected to be usable as direct dependencies:
- matrix-sdk-ui – A high-level client library that makes it easy to build full-featured UI clients with minimal setup. Check out our reference client, multiverse, for an example.
- matrix-sdk – A mid-level client library, ideal for building bots, custom clients, or higher-level abstractions. You can find example usage in the examples directory.
- matrix-sdk-crypto – A standalone encryption state machine with no network I/O, providing end-to-end encryption support for Matrix clients and libraries. See the crypto tutorial for a step-by-step introduction.
All other crates are effectively internal-only and only structured as crates for organizational purposes and to improve compilation times. Direct usage of them is discouraged.
Status
The library is considered production ready and backs multiple client implementations such as Element X [1] [2], Fractal and iamb. Client developers should feel confident to build upon it.
Bindings
The higher-level crates of the Matrix Rust SDK can be embedded in other environments such as Swift, Kotlin, JavaScript, and Node.js. Check out the bindings/ directory to learn more about how to integrate the SDK into your language of choice.