Update readme to more accuratly reflect API

This commit is contained in:
Devin Ragotzy 2020-07-25 08:10:55 -04:00
parent 0ae8c8fe09
commit ea0b6ad530
2 changed files with 21 additions and 14 deletions

View File

@ -1,23 +1,34 @@
Would it be possible to abstract state res into a `ruma-state-res` crate? I've been thinking about something along the lines of Would it be possible to abstract state res into a `ruma-state-res` crate? I've been thinking about something along the lines of
```rust ```rust
// The would need to be Serialize/Deserialize to save state /// StateMap is just a wrapper/deserialize target for a PDU.
struct StateResV2 { struct StateEvent {
content: serde_json::Value,
room_id: RoomId,
event_id: EventId,
// ... and so on
}
/// A mapping of event type and state_key to some value `T`, usually an `EventId`.
pub type StateMap<T> = BTreeMap<(EventType, String), T>;
struct StateResolution {
// Should any information be kept or should all of it be fetched from the // Should any information be kept or should all of it be fetched from the
// StateStore trait?, // StateStore trait?
state_graph: Something, event_map: BTreeMap<EventId, StateEvent>,
// fields for temp storage during resolution?? // fields for temp storage during resolution??
/// The events that conflict and their auth chains.
conflicting_events: StateMap<Vec<EventId>>, conflicting_events: StateMap<Vec<EventId>>,
} }
impl StateResV2 { impl StateResolution {
/// The point of this all add nonconflicting events to the graph /// The point of this all. Resolve the conflicting set of .
/// and resolve and add conflicting events.
fn resolve(&mut self, events: Vec<StateMap<EventId>>) -> StateMap<EventId> { } fn resolve(&mut self, events: Vec<StateMap<EventId>>) -> StateMap<EventId> { }
} }
// The tricky part of making a good abstraction // The tricky part, making a good abstraction...
trait StateStore { trait StateStore {
/// Return a single event based on the EventId. /// Return a single event based on the EventId.
fn get_event(&self, event_id: &EventId) -> Result<StateEvent, String>; fn get_event(&self, event_id: &EventId) -> Result<StateEvent, String>;
@ -27,7 +38,6 @@ trait StateStore {
/// Returns a Vec of the related auth events to the given `event`. /// Returns a Vec of the related auth events to the given `event`.
fn auth_event_ids(&self, room_id: &RoomId, event_ids: &[EventId]) -> Result<Vec<EventId>, String>; fn auth_event_ids(&self, room_id: &RoomId, event_ids: &[EventId]) -> Result<Vec<EventId>, String>;
} }
``` ```

View File

@ -2,13 +2,12 @@ use std::{
cell::RefCell, cell::RefCell,
collections::{BTreeMap, BTreeSet}, collections::{BTreeMap, BTreeSet},
convert::TryFrom, convert::TryFrom,
time::{Duration, SystemTime, UNIX_EPOCH}, time::UNIX_EPOCH,
}; };
use maplit::btreemap; use maplit::btreemap;
use ruma::{ use ruma::{
events::{ events::{
pdu::Pdu,
room::{ room::{
join_rules::JoinRule, join_rules::JoinRule,
member::{MemberEventContent, MembershipState}, member::{MemberEventContent, MembershipState},
@ -17,7 +16,7 @@ use ruma::{
}, },
identifiers::{EventId, RoomId, RoomVersionId, UserId}, identifiers::{EventId, RoomId, RoomVersionId, UserId},
}; };
use serde_json::{from_value as from_json_value, json, Value as JsonValue}; use serde_json::{json, Value as JsonValue};
use state_res::{ResolutionResult, StateEvent, StateMap, StateResolution, StateStore}; use state_res::{ResolutionResult, StateEvent, StateMap, StateResolution, StateStore};
use tracing_subscriber as tracer; use tracing_subscriber as tracer;
@ -290,8 +289,6 @@ fn INITIAL_EDGES() -> Vec<EventId> {
} }
fn do_check(events: &[StateEvent], edges: Vec<Vec<EventId>>, expected_state_ids: Vec<EventId>) { fn do_check(events: &[StateEvent], edges: Vec<Vec<EventId>>, expected_state_ids: Vec<EventId>) {
use itertools::Itertools;
// to activate logging use `RUST_LOG=debug cargo t one_test_only` // to activate logging use `RUST_LOG=debug cargo t one_test_only`
let _ = LOGGER.call_once(|| { let _ = LOGGER.call_once(|| {
tracer::fmt() tracer::fmt()