@@ -386,7 +386,24 @@ where
386
386
387
387
/// Removes the *top* (greatest if max-heap, smallest if min-heap) item from the binary heap and
388
388
/// returns it, without checking if the binary heap is empty.
389
- #[ allow( clippy:: missing_safety_doc) ] // TODO
389
+ ///
390
+ /// # Safety
391
+ ///
392
+ /// The binary heap must not be empty.
393
+ ///
394
+ /// # Example
395
+ ///
396
+ /// ```
397
+ /// use heapless::binary_heap::{BinaryHeap, Max};
398
+ ///
399
+ /// let mut heap: BinaryHeap<_, Max, 8> = BinaryHeap::new();
400
+ /// heap.push(42)?;
401
+ ///
402
+ /// // SAFETY: We just pushed a number onto the heap, so it cannot be empty.
403
+ /// let val = unsafe { heap.pop_unchecked() };
404
+ /// assert_eq!(val, 42);
405
+ /// # Ok::<(), u8>(())
406
+ /// ```
390
407
pub unsafe fn pop_unchecked ( & mut self ) -> T {
391
408
let mut item = self . data . pop_unchecked ( ) ;
392
409
@@ -420,7 +437,23 @@ where
420
437
}
421
438
422
439
/// Pushes an item onto the binary heap without first checking if it's full.
423
- #[ allow( clippy:: missing_safety_doc) ] // TODO
440
+ ///
441
+ /// # Safety
442
+ ///
443
+ /// The binary heap must not be full.
444
+ ///
445
+ /// # Example
446
+ ///
447
+ /// ```
448
+ /// use heapless::binary_heap::{BinaryHeap, Max};
449
+ ///
450
+ /// let mut heap: BinaryHeap<_, Max, 8> = BinaryHeap::new();
451
+ ///
452
+ /// // SAFETY: We just created an empty heap of size 8, so it cannot be full.
453
+ /// unsafe { heap.push_unchecked(42) };
454
+ /// assert_eq!(heap.len(), 1);
455
+ /// assert_eq!(heap.peek(), Some(&42));
456
+ /// ```
424
457
pub unsafe fn push_unchecked ( & mut self , item : T ) {
425
458
let old_len = self . len ( ) ;
426
459
self . data . push_unchecked ( item) ;
0 commit comments