Skip to content

Commit 5837ac2

Browse files
committed
Implement From<[T; N]> for BinaryHeap<T>
Port rust-lang/rust PR's implementing `From<[T; N]>` for `BinaryHeap<T>`: - #84111: "Stabilize `impl From<[(K, V); N]> for HashMap` (and friends)" - #88611: "Deprecate array::IntoIter::new." NOTE: This requires Rust 1.56.0 or greater.
1 parent 0e5ce1a commit 5837ac2

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ fn main() {
77
// Required for stabilization of `unsafe_op_in_unsafe_fn` lint.
88
ac.emit_rustc_version(1, 52);
99

10-
// Required for stabilization of `Vec::shrink_to()`.
10+
// Required for stabilization of `Vec::shrink_to()` and `IntoIterator` for arrays.
1111
ac.emit_rustc_version(1, 56);
1212

1313
autocfg::rerun_path("build.rs");

src/binary_heap.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1666,6 +1666,25 @@ impl<T: Ord> From<Vec<T>> for BinaryHeap<T> {
16661666
}
16671667
}
16681668

1669+
/// # Compatibility
1670+
///
1671+
/// This trait is only implemented for Rust 1.56.0 or greater.
1672+
#[cfg(rustc_1_56)]
1673+
impl<T: Ord, const N: usize> From<[T; N]> for BinaryHeap<T> {
1674+
/// ```
1675+
/// use binary_heap_plus::BinaryHeap;
1676+
///
1677+
/// let mut h1 = BinaryHeap::from([1, 4, 2, 3]);
1678+
/// let mut h2: BinaryHeap<_> = [1, 4, 2, 3].into();
1679+
/// while let Some((a, b)) = h1.pop().zip(h2.pop()) {
1680+
/// assert_eq!(a, b);
1681+
/// }
1682+
/// ```
1683+
fn from(arr: [T; N]) -> Self {
1684+
Self::from_iter(arr)
1685+
}
1686+
}
1687+
16691688
/// # Compatibility
16701689
///
16711690
/// This trait is only implemented for Rust 1.41.0 or greater. For earlier versions, `Into<Vec<T>>`

0 commit comments

Comments
 (0)