13个版本 (破坏性更新)

0.11.0 2024年5月9日
0.10.0 2023年10月5日
0.9.1 2023年2月15日
0.8.0 2022年9月12日
0.2.0 2021年6月21日

#1455 in Web编程

Download history 71/week @ 2024-04-27 188/week @ 2024-05-04 93/week @ 2024-05-11 121/week @ 2024-05-18 120/week @ 2024-05-25 98/week @ 2024-06-01 34/week @ 2024-06-08 56/week @ 2024-06-15 51/week @ 2024-06-22 14/week @ 2024-06-29 12/week @ 2024-07-06 63/week @ 2024-07-13 64/week @ 2024-07-20 112/week @ 2024-07-27 37/week @ 2024-08-03 54/week @ 2024-08-10

每月274次下载
12 个crate中使用(通过 ruma

MIT 协议

1.5MB
26K SLoC

Rust的Matrix状态解析!

/// Abstraction of a PDU so users can have their own PDU types.
pub trait Event {
    /// The `EventId` of this event.
    fn event_id(&self) -> &EventId;
    /// The `RoomId` of this event.
    fn room_id(&self) -> &RoomId;
    /// The `UserId` of this event.
    fn sender(&self) -> &UserId;
    // and so on...
}

/// A mapping of event type and state_key to some value `T`, usually an `EventId`.
pub type StateMap<T> = BTreeMap<(StateEventType, Option<String>), T>;

/// A mapping of `EventId` to `T`, usually a `OriginalStateEvent`.
pub type EventMap<T> = BTreeMap<OwnedEventId, T>;

struct StateResolution {
    // For now the StateResolution struct is empty. If "caching" `event_map`
    // between `resolve` calls ends up being more efficient (probably not, as this would eat memory)
    // it may have an `event_map` field. The `event_map` is all the events
    // `StateResolution` has to know about to resolve state.
}

impl StateResolution {
    /// The point of this all, resolve the possibly conflicting sets of events.
    pub fn resolve<E: Event>(
        room_id: &RoomId,
        room_version: &RoomVersionId,
        state_sets: &[StateMap<OwnedEventId>],
        auth_events: Vec<Vec<OwnedEventId>>,
        event_map: &mut EventMap<Arc<E>>,
    ) -> Result<StateMap<OwnedEventId>> {;
}

StateStore trait 是对服务器(或甚至客户端)用于存储持久数据单元的数据库的抽象。

在反序列化任何PDU或其内容时,我们使用 ruma 的类型,这有助于避免许多类型检查逻辑,这些逻辑在 synapse 认证事件链时必须执行。

依赖关系

~8–20MB
~300K SLoC