types/crates/ruma-state-res
2023-10-12 15:44:00 +02:00
..
benches Bring back ruma-events 2023-08-28 10:23:54 +02:00
src identifiers: Don't require room IDs to contain a server name 2023-09-28 16:43:16 +02:00
.clippy.toml Remove msrv from .clippy.toml 2022-07-19 21:41:15 +02:00
architecture.md Add 'crates/ruma-state-res/' from commit '56bf45c0235701ac6df56993c327d2f97a499ef9' 2021-05-08 00:20:05 +02:00
Cargo.toml Remove 'www.' from ruma.io URLs 2023-10-12 15:44:00 +02:00
CHANGELOG.md Release ruma-state-res 0.10.0 2023-10-05 17:18:04 +02:00
README.md state-res: Update docs 2022-09-22 11:49:17 +02:00

Matrix State Resolution in Rust!

/// 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>> {;
}

The StateStore trait is an abstraction around what ever database your server (or maybe even client) uses to store Persistent Data Units.

We use rumas types when deserializing any PDU or it's contents which helps avoid a lot of type checking logic synapse must do while authenticating event chains.