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:
Ivan Enderlin
2024-03-18 12:18:41 +01:00
parent b2c96b72b0
commit 44029009e4

View File

@@ -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