use errors::{ErrorKind, dump};
use lazy::SimpleAssert;
use std::fmt::Debug;
pub trait PartialEqMust<T: Debug>: Sized + Debug + PartialEq<T> {
fn must_be(self, to: T) -> SimpleAssert<Self> {
if self == to {
self.into()
} else {
ErrorKind::MustEq { to: dump(&to) }.but_got(self)
}
}
fn must_eq(self, to: T) -> SimpleAssert<Self> {
self.must_be(to)
}
fn must_not_be(self, to: T) -> SimpleAssert<Self> {
if self != to {
self.into()
} else {
ErrorKind::MustNotEq { to: dump(&to) }.but_got(self)
}
}
fn must_not_eq(self, to: T) -> SimpleAssert<Self> {
self.must_not_be(to)
}
}
impl<T: Debug, V: Sized> PartialEqMust<T> for V where V: Debug + PartialEq<T> {}
pub trait MustBeBool: PartialEqMust<bool> {
fn must_be_true(self) -> SimpleAssert<Self> {
self.must_eq(true)
}
fn must_be_false(self) -> SimpleAssert<Self> {
self.must_be(false)
}
}
impl<V: ?Sized> MustBeBool for V where V: PartialEqMust<bool> {}
pub trait MustBeDefault: Debug + PartialEq + Default {
fn must_be_default(self) -> SimpleAssert<Self> {
self.must_be(Self::default())
}
fn must_not_be_default(self) -> SimpleAssert<Self> {
self.must_not_be(Self::default())
}
}
impl<V: ?Sized> MustBeDefault for V where V: Debug + PartialEq + Default {}
fn _assert() {
fn partial_eq<T: PartialEqMust<To>, To: Debug>() {}
fn be_default<T: MustBeDefault>() {}
fn be_bool<T: MustBeBool>() {}
partial_eq::<&str, &str>();
partial_eq::<String, &str>();
partial_eq::<Vec<u8>, Vec<u8>>();
partial_eq::<[u8; 32], [u8; 32]>();
partial_eq::<&[u8], &[u8]>();
be_default::<Option<i64>>();
be_default::<i64>();
be_bool::<bool>();
}