Skip to content

Commit e01dcd3

Browse files
committed
Auto merge of #393 - JustForFun88:rawtableinner_ctrl, r=Amanieu
Doc `RawTableInner::ctrl`
2 parents 179344d + 7b32015 commit e01dcd3

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
@@ -1803,9 +1803,32 @@ impl<A: Allocator + Clone> RawTableInner<A> {
18031803
}
18041804

18051805
/// Returns a pointer to a control byte.
1806+
///
1807+
/// # Safety
1808+
///
1809+
/// For the allocated [`RawTableInner`], the result is [`Undefined Behavior`],
1810+
/// if the `index` is greater than the `self.bucket_mask + 1 + Group::WIDTH`.
1811+
/// In that case, calling this function with `index == self.bucket_mask + 1 + Group::WIDTH`
1812+
/// will return a pointer to the end of the allocated table and it is useless on its own.
1813+
///
1814+
/// Calling this function with `index >= self.bucket_mask + 1 + Group::WIDTH` on a
1815+
/// table that has not been allocated results in [`Undefined Behavior`].
1816+
///
1817+
/// So to satisfy both requirements you should always follow the rule that
1818+
/// `index < self.bucket_mask + 1 + Group::WIDTH`
1819+
///
1820+
/// Calling this function on [`RawTableInner`] that are not already allocated is safe
1821+
/// for read-only purpose.
1822+
///
1823+
/// See also [`Bucket::as_ptr()`] method, for more information about of properly removing
1824+
/// or saving `data element` from / into the [`RawTable`] / [`RawTableInner`].
1825+
///
1826+
/// [`Bucket::as_ptr()`]: Bucket::as_ptr()
1827+
/// [`Undefined Behavior`]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html
18061828
#[inline]
18071829
unsafe fn ctrl(&self, index: usize) -> *mut u8 {
18081830
debug_assert!(index < self.num_ctrl_bytes());
1831+
// SAFETY: The caller must uphold the safety rules for the [`RawTableInner::ctrl`]
18091832
self.ctrl.as_ptr().add(index)
18101833
}
18111834

0 commit comments

Comments
 (0)