Skip to content

Commit c42ce9c

Browse files
committed
chore(sdk): Add an Event type alias for the sake of convenience.
This patch adds an `Event` type alias to `SyncTimelineEvent` to (i) make the code shorter, (ii) remove some cognitive effort, (iii) make things more convenient.
1 parent 40f4fc1 commit c42ce9c

File tree

1 file changed

+12
-9
lines changed
  • crates/matrix-sdk/src/event_cache

1 file changed

+12
-9
lines changed

crates/matrix-sdk/src/event_cache/store.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ use matrix_sdk_common::deserialized_responses::SyncTimelineEvent;
1818

1919
use super::linked_chunk::{Chunk, ChunkIdentifier, Error, Iter, LinkedChunk, Position};
2020

21+
/// An alias for the real event type.
22+
pub type Event = SyncTimelineEvent;
23+
2124
#[derive(Clone, Debug)]
2225
pub struct Gap {
2326
/// The token to use in the query, extracted from a previous "from" /
@@ -28,7 +31,7 @@ pub struct Gap {
2831
const DEFAULT_CHUNK_CAPACITY: usize = 128;
2932

3033
pub struct RoomEvents {
31-
chunks: LinkedChunk<DEFAULT_CHUNK_CAPACITY, SyncTimelineEvent, Gap>,
34+
chunks: LinkedChunk<DEFAULT_CHUNK_CAPACITY, Event, Gap>,
3235
}
3336

3437
impl Default for RoomEvents {
@@ -52,7 +55,7 @@ impl RoomEvents {
5255
/// The last event in `events` is the most recent one.
5356
pub fn push_events<I>(&mut self, events: I)
5457
where
55-
I: IntoIterator<Item = SyncTimelineEvent>,
58+
I: IntoIterator<Item = Event>,
5659
I::IntoIter: ExactSizeIterator,
5760
{
5861
self.chunks.push_items_back(events)
@@ -66,7 +69,7 @@ impl RoomEvents {
6669
/// Insert events at a specified position.
6770
pub fn insert_events_at<I>(&mut self, events: I, position: Position) -> Result<(), Error>
6871
where
69-
I: IntoIterator<Item = SyncTimelineEvent>,
72+
I: IntoIterator<Item = Event>,
7073
I::IntoIter: ExactSizeIterator,
7174
{
7275
self.chunks.insert_items_at(events, position)
@@ -88,9 +91,9 @@ impl RoomEvents {
8891
&mut self,
8992
events: I,
9093
gap_identifier: ChunkIdentifier,
91-
) -> Result<&Chunk<DEFAULT_CHUNK_CAPACITY, SyncTimelineEvent, Gap>, Error>
94+
) -> Result<&Chunk<DEFAULT_CHUNK_CAPACITY, Event, Gap>, Error>
9295
where
93-
I: IntoIterator<Item = SyncTimelineEvent>,
96+
I: IntoIterator<Item = Event>,
9497
I::IntoIter: ExactSizeIterator,
9598
{
9699
self.chunks.replace_gap_at(events, gap_identifier)
@@ -99,29 +102,29 @@ impl RoomEvents {
99102
/// Search for a chunk, and return its identifier.
100103
pub fn chunk_identifier<'a, P>(&'a self, predicate: P) -> Option<ChunkIdentifier>
101104
where
102-
P: FnMut(&'a Chunk<DEFAULT_CHUNK_CAPACITY, SyncTimelineEvent, Gap>) -> bool,
105+
P: FnMut(&'a Chunk<DEFAULT_CHUNK_CAPACITY, Event, Gap>) -> bool,
103106
{
104107
self.chunks.chunk_identifier(predicate)
105108
}
106109

107110
/// Iterate over the chunks, forward.
108111
///
109112
/// The oldest chunk comes first.
110-
pub fn chunks(&self) -> Iter<'_, DEFAULT_CHUNK_CAPACITY, SyncTimelineEvent, Gap> {
113+
pub fn chunks(&self) -> Iter<'_, DEFAULT_CHUNK_CAPACITY, Event, Gap> {
111114
self.chunks.chunks()
112115
}
113116

114117
/// Iterate over the events, backward.
115118
///
116119
/// The most recent event comes first.
117-
pub fn revents(&self) -> impl Iterator<Item = (Position, &SyncTimelineEvent)> {
120+
pub fn revents(&self) -> impl Iterator<Item = (Position, &Event)> {
118121
self.chunks.ritems()
119122
}
120123

121124
/// Iterate over the events, forward.
122125
///
123126
/// The oldest event comes first.
124-
pub fn events(&self) -> impl Iterator<Item = (Position, &SyncTimelineEvent)> {
127+
pub fn events(&self) -> impl Iterator<Item = (Position, &Event)> {
125128
self.chunks.items()
126129
}
127130
}

0 commit comments

Comments
 (0)