Skip to content

Commit db9ee9d

Browse files
committed
refactor: Add constructors for Position and ChunkIdentifier.
This patch adds constructors for `Position` and `ChunkIdentifier` so that we keep their inner values private.
1 parent 1dbb494 commit db9ee9d

File tree

2 files changed

+114
-76
lines changed

2 files changed

+114
-76
lines changed

crates/matrix-sdk-common/src/linked_chunk/mod.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -934,7 +934,19 @@ impl ChunkIdentifierGenerator {
934934
/// Learn more with [`ChunkIdentifierGenerator`].
935935
#[derive(Copy, Clone, Debug, PartialEq)]
936936
#[repr(transparent)]
937-
pub struct ChunkIdentifier(pub(super) u64);
937+
pub struct ChunkIdentifier(u64);
938+
939+
impl ChunkIdentifier {
940+
/// Create a new [`ChunkIdentifier`].
941+
pub(super) fn new(identifier: u64) -> Self {
942+
Self(identifier)
943+
}
944+
945+
/// Get the underlying identifier.
946+
fn index(&self) -> u64 {
947+
self.0
948+
}
949+
}
938950

939951
impl PartialEq<u64> for ChunkIdentifier {
940952
fn eq(&self, other: &u64) -> bool {
@@ -946,9 +958,14 @@ impl PartialEq<u64> for ChunkIdentifier {
946958
///
947959
/// It's a pair of a chunk position and an item index.
948960
#[derive(Copy, Clone, Debug, PartialEq)]
949-
pub struct Position(pub(super) ChunkIdentifier, pub(super) usize);
961+
pub struct Position(ChunkIdentifier, usize);
950962

951963
impl Position {
964+
/// Create a new [`Position`].
965+
pub(super) fn new(chunk_identifier: ChunkIdentifier, index: usize) -> Self {
966+
Self(chunk_identifier, index)
967+
}
968+
952969
/// Get the chunk identifier of the item.
953970
pub fn chunk_identifier(&self) -> ChunkIdentifier {
954971
self.0

0 commit comments

Comments
 (0)