Skip to content

Commit efa1b19

Browse files
committed
comments: add precondition comments
Add `/// Preconditiion:` comments replacing the `#[pre()]` macros since we are no longer using the `pre` crate. Signed-off-by: Dan Cross <[email protected]>
1 parent 334c1fc commit efa1b19

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/group.rs

+7
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,8 @@ impl GroupMutIter<'_> {
392392
}
393393
}
394394
/// Inserts the given entry data at the right spot.
395+
/// Precondition: The caller already grew the group by
396+
/// `payload_size + size_of::<ENTRY_HEADER>()`
395397
#[allow(clippy::too_many_arguments)]
396398
pub(crate) fn insert_entry(
397399
&mut self,
@@ -566,6 +568,9 @@ impl GroupMutItem<'_> {
566568
Ok(entry_size as u32)
567569
}
568570
/// Resizes the given entry by SIZE_DIFF.
571+
/// Precondition: If `size_diff > 0`, the caller must have already
572+
/// expanded the group `size_diff`. If `size_diff < 0`, the caller
573+
/// must call `resize_entry_by` before resizing the group.
569574
pub(crate) fn resize_entry_by(
570575
&mut self,
571576
entry_id: EntryId,
@@ -634,6 +639,8 @@ impl GroupMutItem<'_> {
634639
}
635640
}
636641
/// Inserts the given token.
642+
/// Precondition: Caller already increased the group size by
643+
/// `size_of::<TOKEN_ENTRY>()`.
637644
pub(crate) fn insert_token(
638645
&mut self,
639646
entry_id: EntryId,

src/tokens_entry.rs

+4
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,8 @@ impl<'a> TokensEntryIter<&'a mut [u8]> {
203203
}
204204

205205
/// Inserts the given entry data at the right spot.
206+
/// Precondition: Caller must have already increased the group size
207+
/// by `size_of::<TOKEN_ENTRY>()`.
206208
pub(crate) fn insert_token(
207209
&mut self,
208210
token_id: u32,
@@ -602,6 +604,8 @@ impl TokensEntryBodyItem<&mut [u8]> {
602604
(self.iter_mut().ok()?).find(|entry| entry.id() == token_id)
603605
}
604606

607+
/// Precondition: Caller already increased the group size by
608+
/// `size_of::<TOKEN_ENTRY>()`.
605609
pub(crate) fn insert_token(
606610
&mut self,
607611
token_id: u32,

0 commit comments

Comments
 (0)