Skip to content

Commit 79aeb5a

Browse files
committed
BinaryHeap: fix missing safety doc
1 parent 2e71c18 commit 79aeb5a

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/binary_heap.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,25 @@ where
389389

390390
/// Removes the *top* (greatest if max-heap, smallest if min-heap) item from the binary heap and
391391
/// returns it, without checking if the binary heap is empty.
392-
#[allow(clippy::missing_safety_doc)] // TODO
392+
///
393+
/// # Safety
394+
///
395+
/// The binary heap must not be empty.
396+
///
397+
/// # Example
398+
///
399+
/// ```
400+
/// use heapless::binary_heap::{BinaryHeap, Max};
401+
///
402+
/// let mut heap: BinaryHeap<_, Max, 8> = BinaryHeap::new();
403+
/// heap.push(42).unwrap();
404+
///
405+
/// if !heap.is_empty() {
406+
/// // SAFETY: the heap is not empty
407+
/// let val = unsafe { heap.pop_unchecked() };
408+
/// assert_eq!(val, 42);
409+
/// }
410+
/// ```
393411
pub unsafe fn pop_unchecked(&mut self) -> T {
394412
let mut item = self.data.pop_unchecked();
395413

0 commit comments

Comments
 (0)