pub struct PeekMut<'a, T, A = Global>where
T: 'a + Ord,
A: Allocator,{ /* private fields */ }
Structure wrapping a mutable reference to the greatest item on a BinaryHeap.
This struct is created by the peek_mut method on BinaryHeap. See its documentation for more.
impl<'a, T, A> PeekMut<'a, T, A>where
T: Ord,
A: Allocator,pub fn refresh(&mut self) -> bool
binary_heap_peek_mut_refresh #138355)
Sifts the current element to its new position.
Afterwards refers to the new element. Returns if the element changed.
The condition can be used to upper bound all elements in the heap. When only few elements are affected, the heap’s sort ensures this is faster than a reconstruction from the raw element list and requires no additional allocation.
#![feature(binary_heap_peek_mut_refresh)]
use std::collections::BinaryHeap;
let mut heap: BinaryHeap<u32> = (0..128).collect();
let mut peek = heap.peek_mut().unwrap();
loop {
*peek = 99;
if !peek.refresh() {
break;
}
}
// Post condition, this is now an upper bound.
assert!(*peek < 100);When the element remains the maximum after modification, the peek remains unchanged:
#![feature(binary_heap_peek_mut_refresh)] use std::collections::BinaryHeap; let mut heap: BinaryHeap<u32> = [1, 2, 3].into(); let mut peek = heap.peek_mut().unwrap(); assert_eq!(*peek, 3); *peek = 42; // When we refresh, the peek is updated to the new maximum. assert!(!peek.refresh(), "42 is even larger than 3"); assert_eq!(*peek, 42);
pub fn pop(this: PeekMut<'a, T, A>) -> T
Removes the peeked value from the heap and returns it.
impl<T, A> Debug for PeekMut<'_, T, A>where
T: Ord + Debug,
A: Allocator,fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>
impl<T, A> Deref for PeekMut<'_, T, A>where
T: Ord,
A: Allocator,type Target = T
fn deref(&self) -> &T
impl<T, A> DerefMut for PeekMut<'_, T, A>where
T: Ord,
A: Allocator,fn deref_mut(&mut self) -> &mut T
impl<T, A> Drop for PeekMut<'_, T, A>where
T: Ord,
A: Allocator,impl<'a, T, A> Freeze for PeekMut<'a, T, A>
impl<'a, T, A> RefUnwindSafe for PeekMut<'a, T, A>where
A: RefUnwindSafe,
T: RefUnwindSafe,impl<'a, T, A> Send for PeekMut<'a, T, A>where
A: Send,
T: Send,impl<'a, T, A> Sync for PeekMut<'a, T, A>where
A: Sync,
T: Sync,impl<'a, T, A> Unpin for PeekMut<'a, T, A>
impl<'a, T, A = Global> !UnwindSafe for PeekMut<'a, T, A>
impl<T> Any for Twhere
T: 'static + ?Sized,impl<T> Borrow<T> for Twhere
T: ?Sized,impl<T> BorrowMut<T> for Twhere
T: ?Sized,impl<T> From<T> for T
fn from(t: T) -> T
Returns the argument unchanged.
impl<T, U> Into<U> for Twhere
U: From<T>,fn into(self) -> U
Calls U::from(self).
That is, this conversion is whatever the implementation of From<T> for U chooses to do.
impl<P, T> Receiver for Pwhere
P: Deref<Target = T> + ?Sized,
T: ?Sized,type Target = T
arbitrary_self_types #44874)
impl<T, U> TryFrom<U> for Twhere
U: Into<T>,type Error = Infallible
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto<U> for Twhere
U: TryFrom<T>,
© 2010 The Rust Project Developers
Licensed under the Apache License, Version 2.0 or the MIT license, at your option.
https://doc.rust-lang.org/std/collections/binary_heap/struct.PeekMut.html