From f81f497efe721d11f6f582ad471283521b8c70a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sosth=C3=A8ne=20Gu=C3=A9don?= Date: Thu, 27 Jun 2024 13:50:25 +0200 Subject: [PATCH] Add missing documentation --- src/binary_heap.rs | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/src/binary_heap.rs b/src/binary_heap.rs index d43675492b..6cd604ef27 100644 --- a/src/binary_heap.rs +++ b/src/binary_heap.rs @@ -125,7 +125,7 @@ pub type BinaryHeap = private::BinaryHeapInner = BinaryHeap::new(); -/// let mut heap_view: &mut BinaryHeapView<_, Max> = &mut heap; +/// let heap_view: &mut BinaryHeapView<_, Max> = &mut heap; /// /// // We can use peek to look at the next item in the heap_view. In this case, /// // there's no items in there yet so we get None. @@ -183,10 +183,44 @@ impl BinaryHeap { } } + /// Get a reference to the `BinaryHeap`, erasing the `N` const-generic + /// + /// ``` + /// # use heapless::{BinaryHeap, BinaryHeapView, binary_heap::Max}; + /// + /// let heap: BinaryHeap = BinaryHeap::new(); + /// let heap_view: &BinaryHeapView<_, _> = heap.as_view(); + /// ```` + /// + /// It is often preferable to do the same through type coerction, since `BinaryHeap` implements `Unsize>`: + /// + /// ```rust + /// # use heapless::{BinaryHeap, BinaryHeapView, binary_heap::Max}; + /// + /// let heap: BinaryHeap = BinaryHeap::new(); + /// let heap_view: &BinaryHeapView<_, _> = &heap; + /// ``` pub fn as_view(&self) -> &BinaryHeapView { self } + /// Get a mutable reference to the `BinaryHeap`, erasing the `N` const-generic + /// + /// ``` + /// # use heapless::{BinaryHeap, BinaryHeapView, binary_heap::Max}; + /// + /// let mut heap: BinaryHeap = BinaryHeap::new(); + /// let heap_view: &mut BinaryHeapView<_, _> = heap.as_mut_view(); + /// ```` + /// + /// It is often preferable to do the same through type coerction, since `BinaryHeap` implements `Unsize>`: + /// + /// ```rust + /// # use heapless::{BinaryHeap, BinaryHeapView, binary_heap::Max}; + /// + /// let mut heap: BinaryHeap = BinaryHeap::new(); + /// let heap_view: &mut BinaryHeapView<_, _> = &mut heap; + /// ``` pub fn as_mut_view(&mut self) -> &mut BinaryHeapView { self }