pub struct IsAscii<T>(pub T);
impl IsAscii<&[u8]> {
pub const fn const_eval(&self) -> bool {
let bytes = self.0;
let mut i = 0;
while i < bytes.len() {
if !bytes[i].is_ascii() {
return false;
}
i += 1;
}
true
}
}
impl IsAscii<&str> {
pub const fn const_eval(&self) -> bool {
IsAscii(self.0.as_bytes()).const_eval()
}
}
impl<const N: usize> IsAscii<&[u8; N]> {
pub const fn const_eval(&self) -> bool {
IsAscii(self.0.as_slice()).const_eval()
}
}
#[macro_export]
macro_rules! is_ascii {
($s:expr) => {
$crate::__ctfe::IsAscii($s).const_eval()
};
}