From 594082cbdae8445443754ea271fb3a76013535de Mon Sep 17 00:00:00 2001 From: Devin Ragotzy Date: Sun, 24 Jan 2021 20:56:04 -0500 Subject: [PATCH] Update readme to how the library is set up now --- README.md | 39 ++++++++++++++++----------------------- 1 file changed, 16 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 91f28152..a547805d 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,19 @@ ### Matrix state resolution in rust! ```rust -/// StateMap is just a wrapper/deserialize target for a PDU. -struct StateEvent { - content: serde_json::Value, - origin_server_ts: SystemTime, - sender: UserId, - // ... and so on +/// 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 = BTreeMap<(EventType, String), T>; +pub type StateMap = BTreeMap<(EventType, Option), T>; /// A mapping of `EventId` to `T`, usually a `StateEvent`. pub type EventMap = BTreeMap; @@ -18,32 +21,22 @@ pub type EventMap = BTreeMap; 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 event's - // `StateResolution` has to know about in order to resolve state. + // 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( + pub fn resolve( room_id: &RoomId, room_version: &RoomVersionId, state_sets: &[StateMap], - event_map: Option>, - store: &dyn StateStore, - ) -> Result, Error>; + auth_events: Vec>, + event_map: &mut EventMap>, + ) -> Result> {; } -// The tricky part, making a good abstraction... -trait StateStore { - /// Return a single event based on the EventId. - fn get_event(&self, room_id: &RoomId, event_id: &EventId) -> Result; - - // There are 3 methods that have default implementations `get_events`, - // `auth_event_ids` and `auth_chain_diff`. Each could be overridden if - // the user has an optimization with their database of choice. -} - ```