mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-05-09 00:15:23 -04:00
feat(sdk): Implement ChunkIdentifier::to_last_item_position.
This patch is about an internal thing, but it makes the code easier to understand.
This commit is contained in:
@@ -402,7 +402,7 @@ impl<Item, Gap, const CAP: usize> LinkedChunk<Item, Gap, CAP> {
|
||||
///
|
||||
/// It iterates from the last to the first item.
|
||||
pub fn ritems(&self) -> impl Iterator<Item = (ItemPosition, &Item)> {
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user