usecrate::TinyAsciiStr; usecrate::TinyStrError; use core::fmt;
/// A fixed-length bytes array that is expected to be an ASCII string but does not enforce that invariant. /// /// Use this type instead of `TinyAsciiStr` if you don't need to enforce ASCII during deserialization. For /// example, strings that are keys of a map don't need to ever be reified as `TinyAsciiStr`s. /// /// The main advantage of this type over `[u8; N]` is that it serializes as a string in /// human-readable formats like JSON. #[derive(PartialEq, PartialOrd, Eq, Ord, Clone, Copy)] pubstruct UnvalidatedTinyAsciiStr<const N: usize>(pub(crate) [u8; N]);
impl<const N: usize> fmt::Debug for UnvalidatedTinyAsciiStr<N> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { // Debug as a string if possible matchself.try_into_tinystr() {
Ok(s) => fmt::Debug::fmt(&s, f),
Err(_) => fmt::Debug::fmt(&self.0, f),
}
}
}
impl<const N: usize> UnvalidatedTinyAsciiStr<N> { #[inline] // Converts into a [`TinyAsciiStr`]. Fails if the bytes are not valid ASCII. pubfn try_into_tinystr(&self) -> Result<TinyAsciiStr<N>, TinyStrError> {
TinyAsciiStr::try_from_raw(self.0)
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.