TopicMap

Trait TopicMap 

Source
pub trait TopicMap<T, V>: Clone {
    type Error: StdError;

    // Required method
    fn get(&self, topic: &T) -> impl Future<Output = Result<V, Self::Error>>;
}
Expand description

Maps a topic to a user defined data type being sent over the wire during sync.

It defines the type of data it is expecting to sync and how the scope for a particular session should be identified; users provide an implementation of the TopicMap trait in order to define how this mapping occurs.

Since TopicMap is generic we can use the same mapping across different sync implementations for the same data type when necessary.

For example a TopicMap map implementation could map a generic T to a set of logs.

§Designing TopicMap for applications

Considering an example chat application which is based on append-only log data types, we probably want to organise messages from an author for a certain chat group into one log each. Like this, a chat group can be expressed as a collection of one to potentially many logs (one per member of the group):

All authors: A, B and C
All chat groups: 1 and 2

"Chat group 1 with members A and B"
- Log A1
- Log B1

"Chat group 2 with members A, B and C"
- Log A2
- Log B2
- Log C2

If we implement T to express that we’re interested in syncing over a specific chat group, for example “Chat Group 2” we would implement TopicMap to give us all append-only logs of all members inside this group, that is the entries inside logs A2, B2 and C2.

Required Associated Types§

Required Methods§

Source

fn get(&self, topic: &T) -> impl Future<Output = Result<V, Self::Error>>

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§