#[cfg(feature = "simdutf8")]
use simdutf8::basic as simd_utf8;
#[inline]
pub fn validate(bytes: &[u8]) -> Result<&str, ()> {
#[cfg(feature = "simdutf8")]
{
simd_utf8::from_utf8(bytes).map_err(|_| ())
}
#[cfg(not(feature = "simdutf8"))]
{
core::str::from_utf8(bytes).map_err(|_| ())
}
}
#[cfg(feature = "unsafe-utf8")]
#[inline]
#[allow(clippy::unnecessary_wraps)]
#[allow(clippy::missing_const_for_fn)]
pub fn trusted(bytes: &[u8]) -> Result<&str, ()> {
Ok(unsafe { core::str::from_utf8_unchecked(bytes) })
}
#[cfg(not(feature = "unsafe-utf8"))]
#[inline]
pub fn trusted(bytes: &[u8]) -> Result<&str, ()> {
validate(bytes)
}