must 0.2.0

assertion library for rust
Documentation
use errors::{ErrorKind, dump};
use lazy::SimpleAssert;
use marker::Cased;
use std::ascii::AsciiExt;
use std::fmt::Debug;


pub trait CasedTextMust: Sized + Debug + Cased {
	/// # Examples
	///
	/// ```rust
	/// #[macro_use] extern crate must;
	/// use must::prelude::*;
	/// # extern crate env_logger;
	/// # fn main() {
	/// # let _ = env_logger::init();
	/// String::from("low").must_be_lowercase();
	/// "low".must_be_lowercase();
	/// 'l'.must_be_lowercase();
	/// # }
	/// ```
	fn must_be_lowercase(self) -> SimpleAssert<Self> {
		if self.is_lower() {
			self.into()
		} else {
			ErrorKind::MustBeLowercase.but_got(self)
		}
	}

	/// # Examples
	///
	/// ```rust
	/// #[macro_use] extern crate must;
	/// use must::prelude::*;
	/// # extern crate env_logger;
	/// # fn main() {
	/// # let _ = env_logger::init();
	/// String::from("UPPER").must_be_uppercase();
	/// "UP".must_be_uppercase();
	/// 'U'.must_be_uppercase();
	/// # }
	/// ```
	fn must_be_uppercase(self) -> SimpleAssert<Self> {
		if self.is_upper() {
			self.into()
		} else {
			ErrorKind::MustBeUppercase.but_got(self)
		}
	}
}

impl<V: Sized> CasedTextMust for V where V: Debug + Cased {}


/// Extension for [AsciiExt][]
///
/// [AsciiExt]:https://doc.rust-lang.org/std/ascii/trait.AsciiExt.html
pub trait MustBeAscii: Sized + Debug + AsciiExt {
	fn must_be_ascii(self) -> SimpleAssert<Self> {
		if self.is_ascii() {
			self.into()
		} else {
			ErrorKind::MustBeAscii.but_got(self)
		}
	}

	fn must_eq_ignore_ascii_case(self, other: &Self) -> SimpleAssert<Self> {
		if self.eq_ignore_ascii_case(other) {
			self.into()
		} else {
			ErrorKind::MustBeEqAsciiIgnoreCase { to: dump(other) }.but_got(self)
		}
	}
}

impl<V> MustBeAscii for V where V: Debug + AsciiExt {}