90: impl more traits for pool::Box and pool::singleton::Box r=japaric a=japaric



Co-authored-by: Jorge Aparicio <jorge@japaric.io>
This commit is contained in:
bors[bot] 2019-04-28 16:55:31 +00:00
commit aab766f764
2 changed files with 95 additions and 2 deletions

View File

@ -152,7 +152,8 @@
use core::{
cell::UnsafeCell,
fmt,
cmp, fmt,
hash::{Hash, Hasher},
marker::PhantomData,
ops::{Deref, DerefMut},
ptr::{self, NonNull},
@ -399,6 +400,47 @@ where
}
}
impl<T> PartialEq for Box<T>
where
T: PartialEq,
{
fn eq(&self, rhs: &Box<T>) -> bool {
<T as PartialEq>::eq(self, rhs)
}
}
impl<T> Eq for Box<T> where T: Eq {}
impl<T> PartialOrd for Box<T>
where
T: PartialOrd,
{
fn partial_cmp(&self, rhs: &Box<T>) -> Option<cmp::Ordering> {
<T as PartialOrd>::partial_cmp(self, rhs)
}
}
impl<T> Ord for Box<T>
where
T: Ord,
{
fn cmp(&self, rhs: &Box<T>) -> cmp::Ordering {
<T as Ord>::cmp(self, rhs)
}
}
impl<T> Hash for Box<T>
where
T: Hash,
{
fn hash<H>(&self, state: &mut H)
where
H: Hasher,
{
<T as Hash>::hash(self, state)
}
}
#[cfg(test)]
mod tests {
use core::{

View File

@ -2,7 +2,8 @@
use core::{
any::TypeId,
fmt,
cmp, fmt,
hash::{Hash, Hasher},
marker::PhantomData,
mem,
ops::{Deref, DerefMut},
@ -219,6 +220,56 @@ where
}
}
impl<P> PartialEq for Box<P>
where
P: Pool,
P::Data: PartialEq,
{
fn eq(&self, rhs: &Box<P>) -> bool {
<P::Data as PartialEq>::eq(self, rhs)
}
}
impl<P> Eq for Box<P>
where
P: Pool,
P::Data: Eq,
{
}
impl<P> PartialOrd for Box<P>
where
P: Pool,
P::Data: PartialOrd,
{
fn partial_cmp(&self, rhs: &Box<P>) -> Option<cmp::Ordering> {
<P::Data as PartialOrd>::partial_cmp(self, rhs)
}
}
impl<P> Ord for Box<P>
where
P: Pool,
P::Data: Ord,
{
fn cmp(&self, rhs: &Box<P>) -> cmp::Ordering {
<P::Data as Ord>::cmp(self, rhs)
}
}
impl<P> Hash for Box<P>
where
P: Pool,
P::Data: Hash,
{
fn hash<H>(&self, state: &mut H)
where
H: Hasher,
{
<P::Data as Hash>::hash(self, state)
}
}
#[cfg(all(test, feature = "min-const-fn"))]
mod tests {
use core::{