Update readme to how the library is set up now
This commit is contained in:
parent
8265247f7a
commit
594082cbda
39
README.md
39
README.md
@ -1,16 +1,19 @@
|
|||||||
### Matrix state resolution in rust!
|
### Matrix state resolution in rust!
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
/// StateMap is just a wrapper/deserialize target for a PDU.
|
/// Abstraction of a PDU so users can have their own PDU types.
|
||||||
struct StateEvent {
|
pub trait Event {
|
||||||
content: serde_json::Value,
|
/// The `EventId` of this event.
|
||||||
origin_server_ts: SystemTime,
|
fn event_id(&self) -> &EventId;
|
||||||
sender: UserId,
|
/// The `RoomId` of this event.
|
||||||
// ... and so on
|
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`.
|
/// A mapping of event type and state_key to some value `T`, usually an `EventId`.
|
||||||
pub type StateMap<T> = BTreeMap<(EventType, String), T>;
|
pub type StateMap<T> = BTreeMap<(EventType, Option<String>), T>;
|
||||||
|
|
||||||
/// A mapping of `EventId` to `T`, usually a `StateEvent`.
|
/// A mapping of `EventId` to `T`, usually a `StateEvent`.
|
||||||
pub type EventMap<T> = BTreeMap<EventId, T>;
|
pub type EventMap<T> = BTreeMap<EventId, T>;
|
||||||
@ -18,32 +21,22 @@ pub type EventMap<T> = BTreeMap<EventId, T>;
|
|||||||
struct StateResolution {
|
struct StateResolution {
|
||||||
// For now the StateResolution struct is empty. If "caching" `event_map`
|
// 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)
|
// 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
|
// it may have an `event_map` field. The `event_map` is all the events
|
||||||
// `StateResolution` has to know about in order to resolve state.
|
// `StateResolution` has to know about to resolve state.
|
||||||
}
|
}
|
||||||
|
|
||||||
impl StateResolution {
|
impl StateResolution {
|
||||||
/// The point of this all, resolve the possibly conflicting sets of events.
|
/// The point of this all, resolve the possibly conflicting sets of events.
|
||||||
pub fn resolve(
|
pub fn resolve<E: Event>(
|
||||||
room_id: &RoomId,
|
room_id: &RoomId,
|
||||||
room_version: &RoomVersionId,
|
room_version: &RoomVersionId,
|
||||||
state_sets: &[StateMap<EventId>],
|
state_sets: &[StateMap<EventId>],
|
||||||
event_map: Option<EventMap<StateEvent>>,
|
auth_events: Vec<Vec<EventId>>,
|
||||||
store: &dyn StateStore,
|
event_map: &mut EventMap<Arc<E>>,
|
||||||
) -> Result<StateMap<EventId>, Error>;
|
) -> Result<StateMap<EventId>> {;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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<StateEvent, Error>;
|
|
||||||
|
|
||||||
// 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.
|
|
||||||
}
|
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user