use errors::ErrorKind;
use lazy::{LazyAssertion, LazyMatcher, SimpleAssert};
use std::fmt::Debug;
pub trait OptionMust<S: Debug>: Sized + Debug {
fn must_be_some(self) -> SimpleAssert<S>;
fn must_be_some_and<F, R>(self, op: F) -> LazyAssertion<R>
where F: FnOnce(S) -> LazyAssertion<R>,
R: LazyMatcher
{
self.must_be_some().and(op)
}
fn must_be_none(self) -> SimpleAssert<()>;
}
impl<S: Debug> OptionMust<S> for Option<S> {
fn must_be_some(self) -> SimpleAssert<S> {
match self {
Some(val) => val.into(),
None => ErrorKind::MustBeSome.but_got(()),
}
}
fn must_be_none(self) -> SimpleAssert<()> {
match self {
Some(val) => ErrorKind::MustBeNone.but_got(val),
None => ().into(),
}
}
}