use const_macros::const_early;
#[cfg(feature = "diagnostics")]
use miette::Diagnostic;
use thiserror::Error;
#[derive(Debug, Error)]
#[error("non-ascii string encountered")]
#[cfg_attr(
feature = "diagnostics",
derive(Diagnostic),
diagnostic(code(pkce_std::check::ascii), help("ensure the string is ASCII"))
)]
pub struct Error;
pub const fn check_str(string: &str) -> Result<(), Error> {
const_early!(!string.is_ascii() => Error);
Ok(())
}
pub fn check<S: AsRef<str>>(string: S) -> Result<(), Error> {
check_str(string.as_ref())
}