Skip to content

Commit

Permalink
Add BinaryHeap implementation.
Browse files Browse the repository at this point in the history
  • Loading branch information
eskimor committed Feb 2, 2024
1 parent 46b1b8f commit 6d8672a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
16 changes: 15 additions & 1 deletion src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use crate::prelude::{
borrow::{Cow, ToOwned},
boxed::Box,
collections::{BTreeMap, BTreeSet, VecDeque},
collections::{BTreeMap, BTreeSet, VecDeque, BinaryHeap},
fmt,
marker::PhantomData,
ops::{Range, RangeInclusive},
Expand Down Expand Up @@ -263,6 +263,20 @@ where
}
}

impl<T> TypeInfo for BinaryHeap<T>
where
T: TypeInfo + 'static,
{
type Identity = Self;

fn type_info() -> Type {
Type::builder()
.path(Path::prelude("BinaryHeap"))
.type_params(type_params![T])
.composite(Fields::unnamed().field(|f| f.ty::<[T]>()))
}
}

impl<T> TypeInfo for Box<T>
where
T: TypeInfo + ?Sized + 'static,
Expand Down
10 changes: 9 additions & 1 deletion src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::{
prelude::{
borrow::Cow,
boxed::Box,
collections::{BTreeMap, BTreeSet},
collections::{BTreeMap, BTreeSet, BinaryHeap},
string::String,
vec,
},
Expand Down Expand Up @@ -132,6 +132,14 @@ fn collections() {
.composite(Fields::unnamed().field(|f| f.ty::<[String]>()))
);

assert_type!(
BinaryHeap<String>,
Type::builder()
.path(Path::prelude("BinaryHeap"))
.type_params(named_type_params![(T, String)])
.composite(Fields::unnamed().field(|f| f.ty::<[String]>()))
);

assert_type!(
std::collections::VecDeque<String>,
TypeDefSequence::new(meta_type::<String>())
Expand Down

0 comments on commit 6d8672a

Please sign in to comment.