From 44029009e4026d0fda23acacaa995f32ca98f550 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Mon, 18 Mar 2024 12:18:41 +0100 Subject: [PATCH] feat(sdk): Implement `ChunkIdentifier::to_last_item_position`. This patch is about an internal thing, but it makes the code easier to understand. --- crates/matrix-sdk/src/event_cache/linked_chunk.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/crates/matrix-sdk/src/event_cache/linked_chunk.rs b/crates/matrix-sdk/src/event_cache/linked_chunk.rs index c13a2a7d2..5173f45bc 100644 --- a/crates/matrix-sdk/src/event_cache/linked_chunk.rs +++ b/crates/matrix-sdk/src/event_cache/linked_chunk.rs @@ -402,7 +402,7 @@ impl LinkedChunk { /// /// It iterates from the last to the first item. pub fn ritems(&self) -> impl Iterator { - self.ritems_from(ItemPosition(self.latest_chunk().identifier(), 0)) + self.ritems_from(self.latest_chunk().identifier().to_last_item_position()) .expect("`iter_items_from` cannot fail because at least one empty chunk must exist") } @@ -553,6 +553,14 @@ impl ChunkIdentifierGenerator { #[repr(transparent)] pub struct ChunkIdentifier(u64); +impl ChunkIdentifier { + /// Transform the `ChunkIdentifier` into an `ItemPosition` representing the + /// last item position. + fn to_last_item_position(self) -> ItemPosition { + ItemPosition(self, 0) + } +} + /// The position of an item in a [`LinkedChunk`]. /// /// It's a pair of a chunk position and an item index. `(…, 0)` represents