Skip to content

Commit efd6c33

Browse files
committed
chore(sdk): Rename LinkedChunkLinks to LinkedChunkEnds.
1 parent ae6f23a commit efd6c33

File tree

1 file changed

+5
-15
lines changed

1 file changed

+5
-15
lines changed

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

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -86,26 +86,16 @@ pub enum LinkedChunkUpdate<Item, Gap> {
8686

8787
/// Links of a `LinkedChunk`, i.e. the first and last [`Chunk`].
8888
///
89-
/// That's an internal type to make the borrow checker happy. Indeed, to add
90-
/// safety around these `NonNull`s, we want to use the borrow checker as much as
91-
/// possible. For example, `Self::latest_chunk_mut` takes `&mut self` and
92-
/// returns `&mut Chunk`, which is great and safe and all. Except that, if the
93-
/// `first` and `last` fields are used directly inside [`LinkedChunk`], the
94-
/// borrow checker considers that `self` is entirely used mutably. Thus, when we
95-
/// use another field of `LinkedChunk` mutably or immutably, it violates the
96-
/// mutability rules. The borrow checker is smart though: If we extract some
97-
/// values in a particular type, which are placed in a single field, the borrow
98-
/// checker knows that the other fields are safe to use mutably or immutably.
99-
/// The checks are per-field, not per-struct. That's why `first` and `last` have
100-
/// been extracted in a separate type, this type.
101-
struct LinkedChunkLinks<const CHUNK_CAPACITY: usize, Item, Gap> {
89+
/// This type was introduced to avoid borrow checking errors when mutably
90+
/// referencing a subset of fields of a `LinkedChunk`.
91+
struct LinkedChunkEnds<const CHUNK_CAPACITY: usize, Item, Gap> {
10292
/// The first chunk.
10393
first: NonNull<Chunk<CHUNK_CAPACITY, Item, Gap>>,
10494
/// The last chunk.
10595
last: Option<NonNull<Chunk<CHUNK_CAPACITY, Item, Gap>>>,
10696
}
10797

108-
impl<const CAP: usize, Item, Gap> LinkedChunkLinks<CAP, Item, Gap> {
98+
impl<const CAP: usize, Item, Gap> LinkedChunkEnds<CAP, Item, Gap> {
10999
/// Get the first chunk, as an immutable reference.
110100
fn first_chunk(&self) -> &Chunk<CAP, Item, Gap> {
111101
unsafe { self.first.as_ref() }
@@ -164,7 +154,7 @@ impl<const CAP: usize, Item, Gap> LinkedChunkLinks<CAP, Item, Gap> {
164154
/// otherwise it will grow in memory for the eternity.
165155
pub struct LinkedChunk<const CHUNK_CAPACITY: usize, Item, Gap> {
166156
/// The links to the chunks, i.e. the first and the last chunk.
167-
links: LinkedChunkLinks<CHUNK_CAPACITY, Item, Gap>,
157+
links: LinkedChunkEnds<CHUNK_CAPACITY, Item, Gap>,
168158
/// The number of items hold by this linked chunk.
169159
length: usize,
170160
/// The generator of chunk identifiers.

0 commit comments

Comments
 (0)