pub struct BinaryHeap<K, T, C = MaxComparator> { /* private fields */ }
Expand description

A priority queue implemented with a binary heap storing key-value pairs.

Unlike the implementation of BinaryHeap in the standard library, it is ok to modify values while in the heap. This is possible through the BinaryHeap::get_mut() method. Updating a value through RefCell or global state, etc however will still result in an invalid heap as the heap won’t get updated automatically.

Examples

use mut_binary_heap::BinaryHeap;

// Type inference lets us omit an explicit type signature (which
// would be `BinaryHeap<i32, i32, MaxComparator>` in this example).
let mut heap: BinaryHeap<_, _> = BinaryHeap::new();

// We can use peek to look at the next item in the heap. In this case,
// there's no items in there yet so we get None.
assert_eq!(heap.peek(), None);

// Let's add some scores...
heap.push(1, 1);
heap.push(2, 5);
heap.push(3, 2);

// Now peek shows the most important item in the heap.
assert_eq!(heap.peek(), Some(&5));

// We can check the length of a heap.
assert_eq!(heap.len(), 3);

// We can iterate over the items in the heap, although they are returned in
// a random order.
for x in &heap {
    println!("key {}, value {}", x.0, x.1);
}

// If we instead pop these scores, they should come back in order.
assert_eq!(heap.pop(), Some(5));
assert_eq!(heap.pop(), Some(2));
assert_eq!(heap.pop(), Some(1));
assert_eq!(heap.pop(), None);

// We can clear the heap of any remaining items.
heap.clear();

// The heap should now be empty.
assert!(heap.is_empty())

A BinaryHeap with a known list of items can be initialized from an iterator and a key selection function

use mut_binary_heap::BinaryHeap;

// This will create a max-heap.
let heap: BinaryHeap<_, _> = BinaryHeap::from([1, 5, 2].iter(), |v| v.clone());

Min-heap

BinaryHeap can also act as a min-heap without requiring Reverse or a custom Ord implementation.

use mut_binary_heap::BinaryHeap;

let mut heap = BinaryHeap::new_min();

// There is no need to wrap values in `Reverse`
heap.push(1, 1);
heap.push(2, 5);
heap.push(3, 2);

// If we pop these scores now, they should come back in the reverse order.
assert_eq!(heap.pop(), Some(1));
assert_eq!(heap.pop(), Some(2));
assert_eq!(heap.pop(), Some(5));
assert_eq!(heap.pop(), None);

Time complexity

methodcost
pushO(1)~
popO(log(n))
peek/peek_mutO(1)
getO(1)
get_mutO(log(n))
contains_keyO(1)

The value for push is an expected cost; the method documentation gives a more detailed analysis. The cost for get_mut contains the cost of dropping the RefMut returned by the function. Getting access is O(1).

Implementations§

source§

impl<K: Hash + Eq, T, C: Compare<T> + Default> BinaryHeap<K, T, C>

source

pub fn new() -> Self

Creates an empty BinaryHeap.

This default version will create a max-heap.

Examples

Basic usage:

use mut_binary_heap::BinaryHeap;
let mut heap: BinaryHeap<i32, i32> = BinaryHeap::new();
heap.push(0, 3);
heap.push(1, 1);
heap.push(2, 5);
assert_eq!(heap.pop(), Some(5));
source

pub fn with_capacity(capacity: usize) -> Self

Creates an empty BinaryHeap with a specific capacity. This preallocates enough memory for capacity elements, so that the BinaryHeap does not have to be reallocated until it contains at least that many values.

This default version will create a max-heap.

Examples

Basic usage:

use mut_binary_heap::BinaryHeap;
let mut heap: BinaryHeap<i32, i32> = BinaryHeap::with_capacity(10);
assert!(heap.capacity_min() >= 10);
heap.push(0, 3);
heap.push(1, 1);
heap.push(2, 5);
assert_eq!(heap.pop(), Some(5));
source§

impl<K: Hash + Eq + Clone, T, C: Compare<T> + Default> BinaryHeap<K, T, C>

source

pub fn from<I: IntoIterator<Item = T>, F: Fn(&T) -> K>( values: I, key_selector: F ) -> Self

source§

impl<K: Hash + Eq, T: Ord> BinaryHeap<K, T, MinComparator>

source

pub fn new_min() -> Self

Creates an empty BinaryHeap.

The _min() version will create a min-heap.

Examples

Basic usage:

use mut_binary_heap::BinaryHeap;
let mut heap = BinaryHeap::new_min();
heap.push(0, 3);
heap.push(1, 1);
heap.push(2, 5);
assert_eq!(heap.pop(), Some(1));
source

pub fn with_capacity_min(capacity: usize) -> Self

Creates an empty BinaryHeap with a specific capacity. This preallocates enough memory for capacity elements, so that the BinaryHeap does not have to be reallocated until it contains at least that many values.

The _min() version will create a min-heap.

Examples

Basic usage:

use mut_binary_heap::BinaryHeap;
let mut heap = BinaryHeap::with_capacity_min(10);
assert!(heap.capacity_min() >= 10);
heap.push(0, 3);
heap.push(1, 1);
heap.push(2, 5);
assert_eq!(heap.pop(), Some(1));
source§

impl<K: Hash + Eq, T, F> BinaryHeap<K, T, FnComparator<F>>where F: Fn(&T, &T) -> Ordering,

source

pub fn new_by(f: F) -> Self

Creates an empty BinaryHeap.

The _by() version will create a heap ordered by given closure.

Examples

Basic usage:

use mut_binary_heap::BinaryHeap;
let mut heap = BinaryHeap::new_by(|a: &i32, b: &i32| b.cmp(a));
heap.push(0, 3);
heap.push(1, 1);
heap.push(2, 5);
assert_eq!(heap.pop(), Some(1));
source

pub fn with_capacity_by(capacity: usize, f: F) -> Self

Creates an empty BinaryHeap with a specific capacity. This preallocates enough memory for capacity elements, so that the BinaryHeap does not have to be reallocated until it contains at least that many values.

The _by() version will create a heap ordered by given closure.

Examples

Basic usage:

use mut_binary_heap::BinaryHeap;
let mut heap = BinaryHeap::with_capacity_by(10, |a: &i32, b: &i32| b.cmp(a));
assert!(heap.capacity_min() >= 10);
heap.push(0, 3);
heap.push(1, 1);
heap.push(2, 5);
assert_eq!(heap.pop(), Some(1));
source§

impl<K: Hash + Eq, T, F, C: Ord> BinaryHeap<K, T, KeyComparator<F>>where F: Fn(&T) -> C,

source

pub fn new_by_sort_key(f: F) -> Self

Creates an empty BinaryHeap.

The _by_sort_key() version will create a heap ordered by key converted by given closure.

Examples

Basic usage:

use mut_binary_heap::BinaryHeap;
let mut heap = BinaryHeap::new_by_sort_key(|a: &i32| a % 4);
heap.push(0, 3);
heap.push(1, 1);
heap.push(2, 5);
assert_eq!(heap.pop(), Some(3));
source

pub fn with_capacity_by_sort_key(capacity: usize, f: F) -> Self

Creates an empty BinaryHeap with a specific capacity. This preallocates enough memory for capacity elements, so that the BinaryHeap does not have to be reallocated until it contains at least that many values.

The _by_sort_key() version will create a heap ordered by key coverted by given closure.

Examples

Basic usage:

use mut_binary_heap::BinaryHeap;
let mut heap = BinaryHeap::with_capacity_by_sort_key(10, |a: &i32| a % 4);
assert!(heap.capacity_min() >= 10);
heap.push(0, 3);
heap.push(1, 1);
heap.push(2, 5);
assert_eq!(heap.pop(), Some(3));
source§

impl<K: Hash + Eq + Clone, T, C: Compare<T>> BinaryHeap<K, T, C>

source

pub fn push(&mut self, key: K, item: T) -> Option<T>

Pushes an item onto the binary heap.

If the heap did not have this key present, None is returned.

If the heap did have this key present, the value is updated, and the old value is returned. The key is not updated, though; this matters for types that can be == without being identical. For more information see the documentation of HashMap::insert.

Examples

Basic usage:

use mut_binary_heap::BinaryHeap;
let mut heap: BinaryHeap<i32, i32> = BinaryHeap::new();
heap.push(0, 3);
heap.push(1, 5);
heap.push(2, 1);

assert_eq!(heap.len(), 3);
assert_eq!(heap.peek(), Some(&5));
Time complexity

The expected cost of push, averaged over every possible ordering of the elements being pushed, and over a sufficiently large number of pushes, is O(1). This is the most meaningful cost metric when pushing elements that are not already in any sorted pattern.

The time complexity degrades if elements are pushed in predominantly ascending order. In the worst case, elements are pushed in ascending sorted order and the amortized cost per push is O(log(n)) against a heap containing n elements.

The worst case cost of a single call to push is O(n). The worst case occurs when capacity is exhausted and needs a resize. The resize cost has been amortized in the previous figures.

source§

impl<K: Hash + Eq, T, C: Compare<T>> BinaryHeap<K, T, C>

source

pub fn peek_mut(&mut self) -> Option<PeekMut<'_, K, T, C>>

Returns a mutable reference to the first item in the binary heap, or None if it is empty.

Note: If the PeekMut value is leaked, the heap may be in an inconsistent state.

Examples

Basic usage:

use mut_binary_heap::BinaryHeap;
let mut heap: BinaryHeap<i32, i32> = BinaryHeap::new();
assert!(heap.peek_mut().is_none());

heap.push(0, 1);
heap.push(1, 5);
heap.push(2, 2);
{
    let mut val = heap.peek_mut().unwrap();
    assert_eq!(*val, 5);
    *val = 0;
}
assert_eq!(heap.peek(), Some(&2));
Time complexity

If the item is modified then the worst case time complexity is O(log(n)), otherwise it’s O(1).

source

pub fn pop(&mut self) -> Option<T>

Removes the greatest item from the binary heap and returns it, or None if it is empty.

Examples

Basic usage:

use mut_binary_heap::BinaryHeap;
let mut heap = BinaryHeap::<_, _>::from([1, 3], |v| v.clone());

assert_eq!(heap.pop(), Some(3));
assert_eq!(heap.pop(), Some(1));
assert_eq!(heap.pop(), None);
Time complexity

The worst case cost of pop on a heap containing n elements is O(log(n)).

source

pub fn pop_with_key(&mut self) -> Option<(K, T)>

Removes the greatest item from the binary heap and returns it as a key-value pair, or None if it is empty.

Examples

Basic usage:

use mut_binary_heap::BinaryHeap;
let mut heap = BinaryHeap::<_,_>::from(vec![1, 3], |v| v.clone());

assert_eq!(heap.pop_with_key(), Some((3, 3)));
assert_eq!(heap.pop_with_key(), Some((1, 1)));
assert_eq!(heap.pop_with_key(), None);
Time complexity

The worst case cost of pop on a heap containing n elements is O(log(n)).

source

pub fn contains_key(&self, key: &K) -> bool

Returns true if the heap contains a value for the given key.

Examples
use mut_binary_heap::BinaryHeap;
let mut heap = BinaryHeap::<_,_>::from([1, 3], |v| v.clone());

assert!(heap.contains_key(&1));
assert!(heap.contains_key(&3));
assert!(!heap.contains_key(&2));
Time complexity

This method runs in O(1) time.

source

pub fn get(&self, key: &K) -> Option<&T>

Returns a reference to the value for a given key or None if the key does not exist.

Examples
use mut_binary_heap::BinaryHeap;
let mut heap = BinaryHeap::<_,_>::from(vec![1, 3], |v| v.clone());

assert_eq!(heap.get(&1), Some(&1));
assert_eq!(heap.get(&2), None);
Time complecity

This method runs in O(1) time.

source

pub fn get_mut<'a>(&'a mut self, key: &'a K) -> Option<RefMut<'a, K, T, C>>

Returns a mutable reference to the value for a given key or None if the key does not exist.

The heap is updated when RefMut is dropped.

Examples
use mut_binary_heap::BinaryHeap;
let mut heap = BinaryHeap::<i32, i32>::from(vec![1, 3], |v| v.clone());

{
    let mut v = heap.get_mut(&1).unwrap();
    assert_eq!(*v, 1);
    *v = 5;
    // Drop updates the heap
}
assert_eq!(heap.peek_with_key(), Some((&1, &5)));
assert_eq!(heap.get(&2), None);
Time complecity
source

pub fn remove(&mut self, key: &K) -> Option<(K, T)>

Removes a key from the heap, returning the (key, value) if the key was previously in the heap.

The key may be any borrowed form of the map’s key type, but Hash and Eq on the borrowed form must match those for the key type.

Example
use mut_binary_heap::BinaryHeap;

let mut heap: BinaryHeap<_, _> = BinaryHeap::new();
heap.push(0, 5);
heap.push(1, 3);
heap.push(2, 6);

assert_eq!(heap.remove(&0), Some((0, 5)));
assert_eq!(heap.remove(&3), None);
assert_eq!(heap.len(), 2);
assert_eq!(heap.pop(), Some(6));
assert_eq!(heap.pop(), Some(3));
source

pub fn reserve(&mut self, additional: usize)

Consumes the BinaryHeap and returns a vector in sorted (ascending) order.

Examples

Basic usage:

use mut_binary_heap::BinaryHeap;

let mut heap = BinaryHeap::<_, _>::from([1, 2, 4, 5, 7], |v| v.clone());
heap.push(0, 6);
heap.push(1, 3);

// let vec = heap.into_sorted_vec();
// assert_eq!(vec, [1, 2, 3, 4, 5, 6, 7]);

Reserves capacity for at least additional more elements to be inserted in the BinaryHeap. The collection may reserve more space to avoid frequent reallocations.

Panics

Panics if the new capacity overflows usize.

Examples

Basic usage:

use mut_binary_heap::BinaryHeap;
let mut heap: BinaryHeap<_, _> = BinaryHeap::new();
heap.reserve(100);
assert!(heap.capacity_min() >= 100);
heap.push(0, 4);
source

pub fn shrink_to_fit(&mut self)

Discards as much additional capacity as possible. The implementation of Vec and HashMap the exact value of the new capacity.

Examples

Basic usage:

use mut_binary_heap::BinaryHeap;
let mut heap: BinaryHeap<i32, i32> = BinaryHeap::with_capacity(100);

assert!(heap.capacity_min() >= 100);
heap.shrink_to_fit();
assert!(heap.capacity_min() >= 0);
source

pub fn shrink_to(&mut self, min_capacity: usize)

Discards capacity with a lower bound. The implementation of Vec and HashMap the exact value of the new capacity.

The capacity will remain at least as large as both the length and the supplied value.

If the current capacity is less than the lower limit, this is a no-op.

Examples
use mut_binary_heap::BinaryHeap;
let mut heap: BinaryHeap<i32, i32> = BinaryHeap::with_capacity(100);

assert!(heap.capacity_min() >= 100);
heap.shrink_to(10);
assert!(heap.capacity_min() >= 10);
source§

impl<K, T, C> BinaryHeap<K, T, C>

source

pub fn iter(&self) -> Iter<'_, K, T>

Returns an iterator visiting all key-value pairs in the underlying vector, in arbitrary order.

Examples

Basic usage:

use mut_binary_heap::BinaryHeap;
let heap = BinaryHeap::<_,_>::from([1, 2, 3, 4], |v| v.clone());

// Print (1, 1), (2, 2), (3, 3), (4, 4) in arbitrary order
for x in heap.iter() {
    println!("key {}, value {}", x.0, x.1);
}
source

pub fn iter_values(&self) -> IterValues<'_, K, T>

Returns an iterator visiting all values in the underlying vector, in arbitrary order.

Examples

Basic usage:

use mut_binary_heap::BinaryHeap;
let heap = BinaryHeap::<_,_>::from([1, 2, 3, 4], |v| v.clone());

// Print 1, 2, 3, 4 in arbitrary order
for x in heap.iter_values() {
    println!("{}", x);
}
source

pub fn iter_keys(&self) -> IterKeys<'_, K, T>

Returns an iterator visiting all keys in the underlying vector, in arbitrary order.

Examples

Basic usage:

use mut_binary_heap::BinaryHeap;
let heap = BinaryHeap::<_,_>::from([1, 2, 3, 4], |v| v.clone());

// Print 1, 2, 3, 4 in arbitrary order
for x in heap.iter_keys() {
    println!("{}", x);
}
source

pub fn into_values(self) -> IntoValues<K, T>

Creates a consuming iterator, that is, one that moves each value out of the heap in arbitrary order. The heap cannot be used after calling this.

See also BinaryHeap::into_iter(), BinaryHeap::into_keys()

source

pub fn into_keys(self) -> IntoKeys<K, T>

Creates a consuming iterator, that is, one that moves each key out of the heap in arbitrary order. The heap cannot be used after calling this.

See also BinaryHeap::into_iter(), BinaryHeap::into_values()

source

pub fn into_iter_sorted(self) -> IntoIterSorted<K, T, C>

Returns an iterator which retrieves elements in heap order. This method consumes the original heap.

Examples

Basic usage:

use mut_binary_heap::BinaryHeap;
let heap = BinaryHeap::<_,_>::from([1, 2, 3, 4, 5], |v| v.clone());

assert_eq!(heap.into_iter_sorted().take(2).collect::<Vec<_>>(), [5, 4]);
source

pub fn peek(&self) -> Option<&T>

Returns the greatest item in the binary heap, or None if it is empty.

Examples

Basic usage:

use mut_binary_heap::BinaryHeap;
let mut heap: BinaryHeap<_, _> = BinaryHeap::new();
assert_eq!(heap.peek(), None);

heap.push(1, 1);
heap.push(2, 5);
heap.push(3, 2);
assert_eq!(heap.peek(), Some(&5));
Time complexity

Cost is O(1) in the worst case.

source

pub fn peek_with_key(&self) -> Option<(&K, &T)>

Returns the greatest item in the binary heap as a key-value pair, or None if it is empty.

Examples

Basic usage:

use mut_binary_heap::BinaryHeap;
let mut heap: BinaryHeap<_, _> = BinaryHeap::new();
assert_eq!(heap.peek(), None);

heap.push(1, 1);
heap.push(2, 5);
heap.push(3, 2);
assert!(heap.peek_mut().is_some());
assert_eq!(heap.peek_mut().unwrap().key_value(), (&2, &5));
Time complexity

Cost is O(1) in the worst case.

source

pub fn capacity(&self) -> (usize, usize)

Returns the number of elements the binary heap can hold without reallocating. Returns a touple with the capacity of the internal vector and hashmap.

Examples

Basic usage:

use mut_binary_heap::BinaryHeap;
let mut heap: BinaryHeap<_, _> = BinaryHeap::with_capacity(100);
assert!(heap.capacity().0 >= 100);
assert!(heap.capacity().1 >= 100);
heap.push(0, 4);
source

pub fn capacity_min(&self) -> usize

Returns the minimum number of elements the binary heap can hold without reallocating.

Examples

Basic usage:

use mut_binary_heap::BinaryHeap;
let mut heap: BinaryHeap<_, _> = BinaryHeap::with_capacity(100);
assert!(heap.capacity_min() >= 100);
heap.push(0, 4);
source

pub fn len(&self) -> usize

Consumes the BinaryHeap and returns the underlying vector in arbitrary order.

Examples

Basic usage:

use mut_binary_heap::BinaryHeap;
let heap = BinaryHeap::<_,_>::from([1, 2, 3, 4, 5, 6, 7], |v| v.clone());
// let vec = heap.into_vec();

// Will print in some order
// for x in vec {
//    println!("{}", x);
// }

Returns the length of the binary heap.

Examples

Basic usage:

use mut_binary_heap::BinaryHeap;
let heap = BinaryHeap::<_,_>::from([1, 3].iter(), |v| v.clone());

assert_eq!(heap.len(), 2);
source

pub fn is_empty(&self) -> bool

Checks if the binary heap is empty.

Examples

Basic usage:

use mut_binary_heap::BinaryHeap;
let mut heap: BinaryHeap<_, _> = BinaryHeap::new();

assert!(heap.is_empty());

heap.push(0, 3);
heap.push(1, 5);
heap.push(2, 1);

assert!(!heap.is_empty());
source

pub fn drain(&mut self) -> Drain<'_, (K, T)>

Clears the binary heap, returning an iterator over the removed elements in arbitrary order. If the iterator is dropped before being fully consumed, it drops the remaining elements in arbitrary order.

The returned iterator keeps a mutable borrow on the heap to optimize its implementation.

Examples

Basic usage:

use mut_binary_heap::BinaryHeap;
let mut heap = BinaryHeap::<_,_>::from([1, 3].iter(), |v| v.clone());

assert!(!heap.is_empty());

for x in heap.drain() {
    println!("key {}, value {}", x.0, x.1);
}

assert!(heap.is_empty());
source

pub fn clear(&mut self)

Drops all items from the binary heap.

Examples

Basic usage:

use mut_binary_heap::BinaryHeap;
let mut heap = BinaryHeap::<_,_>::from([1, 3].iter(), |v| v.clone());

assert!(!heap.is_empty());

heap.clear();

assert!(heap.is_empty());

Trait Implementations§

source§

impl<K: Clone, T: Clone, C: Clone> Clone for BinaryHeap<K, T, C>

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<K: Debug, T: Debug, C> Debug for BinaryHeap<K, T, C>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<K: Hash + Eq, T, C: Compare<T> + Default> Default for BinaryHeap<K, T, C>

source§

fn default() -> BinaryHeap<K, T, C>

Creates an empty BinaryHeap<K, T>.

source§

impl<K: Hash + Eq + Clone, T, C: Compare<T> + Default> FromIterator<(K, T)> for BinaryHeap<K, T, C>

source§

fn from_iter<I: IntoIterator<Item = (K, T)>>(iter: I) -> Self

Creates a value from an iterator. Read more
source§

impl<'a, K, T, C> IntoIterator for &'a BinaryHeap<K, T, C>

§

type Item = (&'a K, &'a T)

The type of the elements being iterated over.
§

type IntoIter = Iter<'a, K, T>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<'a, K: Hash + Eq, T, C: Compare<T>> IntoIterator for &'a mut BinaryHeap<K, T, C>

§

type Item = (&'a K, &'a mut T)

The type of the elements being iterated over.
§

type IntoIter = MutIter<'a, K, T, C>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<K, T, C> IntoIterator for BinaryHeap<K, T, C>

source§

fn into_iter(self) -> IntoIter<K, T>

Creates a consuming iterator, that is, one that moves each key-value pair out of the binary heap in arbitrary order. The binary heap cannot be used after calling this.

Examples

Basic usage:

use mut_binary_heap::BinaryHeap;
let heap = BinaryHeap::<_,_>::from([1, 2, 3, 4].iter(), |v| v.clone());

// Print 1, 2, 3, 4 in arbitrary order
for x in heap.into_iter() {
    // x has type (i32, i32), not (&i32, &i32)
    println!("key {}, value {}", x.0, x.1);
}
§

type Item = (K, T)

The type of the elements being iterated over.
§

type IntoIter = IntoIter<K, T>

Which kind of iterator are we turning this into?

Auto Trait Implementations§

§

impl<K, T, C = MaxComparator> !RefUnwindSafe for BinaryHeap<K, T, C>

§

impl<K, T, C> Send for BinaryHeap<K, T, C>where C: Send, K: Send, T: Send,

§

impl<K, T, C = MaxComparator> !Sync for BinaryHeap<K, T, C>

§

impl<K, T, C> Unpin for BinaryHeap<K, T, C>where C: Unpin, K: Unpin, T: Unpin,

§

impl<K, T, C> UnwindSafe for BinaryHeap<K, T, C>where C: UnwindSafe, K: UnwindSafe, T: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.