Skip to content

Commit 09df718

Browse files
committed
Doc RawTableInner::ctrl
1 parent 7d01f51 commit 09df718

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/raw/mod.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1342,9 +1342,32 @@ impl<A: Allocator + Clone> RawTableInner<A> {
13421342
}
13431343

13441344
/// Returns a pointer to a control byte.
1345+
///
1346+
/// # Safety
1347+
///
1348+
/// For the allocated [`RawTableInner`], the result is [`Undefined Behavior`],
1349+
/// if the `index` is greater than the `self.bucket_mask + 1 + Group::WIDTH`.
1350+
/// In that case, calling this function with `index == self.bucket_mask + 1 + Group::WIDTH`
1351+
/// will return a pointer to the end of the allocated table and it is useless on its own.
1352+
///
1353+
/// Calling this function with `index >= self.bucket_mask + 1 + Group::WIDTH` on a
1354+
/// table that has not been allocated results in [`Undefined Behavior`].
1355+
///
1356+
/// So to satisfy both requirements you should always follow the rule that
1357+
/// `index < self.bucket_mask + 1 + Group::WIDTH`
1358+
///
1359+
/// Calling this function on [`RawTableInner`] that are not already allocated if safe
1360+
/// for read-only purpose.
1361+
///
1362+
/// See also [`Bucket::as_ptr()`] method, for more information about of properly removing
1363+
/// or saving `data element` from / into the [`RawTable`] / [`RawTableInner`].
1364+
///
1365+
/// [`Bucket::as_ptr()`]: Bucket::as_ptr()
1366+
/// [`Undefined Behavior`]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html
13451367
#[inline]
13461368
unsafe fn ctrl(&self, index: usize) -> *mut u8 {
13471369
debug_assert!(index < self.num_ctrl_bytes());
1370+
// SAFETY: The caller must uphold the safety rules for the [`RawTableInner::ctrl`]
13481371
self.ctrl.as_ptr().add(index)
13491372
}
13501373

0 commit comments

Comments
 (0)