must 0.2.0

assertion library for rust
Documentation
use errors::ErrorKind;
use lazy::{LazyAssertion, LazyMatcher, SimpleAssert};
use std::fmt::Debug;


/// Extension for [Option][]
///
/// [Option]:https://doc.rust-lang.org/std/option/enum.Option.html
pub trait OptionMust<S: Debug>: Sized + Debug {
	fn must_be_some(self) -> SimpleAssert<S>;

	/// # Examples
	///
	/// ```rust
	/// #[macro_use] extern crate must;
	/// use must::prelude::*;
	/// # extern crate env_logger;
	/// # fn main() {
	/// # let _ = env_logger::init();
	/// Some("TEXT").must_be_some_and(|val| {
	/// 	val.must_be("TEXT")
	/// });
	/// # }
	/// ```
	/// ```rust,should_panic
	/// #[macro_use] extern crate must;
	/// use must::prelude::*;
	/// # extern crate env_logger;
	/// # fn main() {
	/// # let _ = env_logger::init();
	/// let none: Option<i64> = None;
	/// none.must_be_some_and(|val| {
	/// 	// unreachable!()
	/// 	val.must_be(54)
	/// }); // panics with '() must be Some(_)'
	/// # }
	/// ```
	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(),
		}
	}
}