use errors::{ErrorKind, dump};
use lazy::SimpleAssert;
use marker::Cased;
use std::ascii::AsciiExt;
use std::fmt::Debug;
pub trait CasedTextMust: Sized + Debug + Cased {
fn must_be_lowercase(self) -> SimpleAssert<Self> {
if self.is_lower() {
self.into()
} else {
ErrorKind::MustBeLowercase.but_got(self)
}
}
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 {}
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 {}