use crate::rstd::inlining::*; use super::*; impl Serializable for [u8; N] { fn serialize(&self, serializer: &mut dyn Serializer) { serializer.write(self) } } #[derive(Debug, PartialEq)] pub enum ArrayParseError { Eof, ExtraData(usize), } impl Display for ArrayParseError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { Self::Eof => write!(f, "encountered EOF write parsing an array"), Self::ExtraData(length) => write!( f, "encountered extra data of length {length} while parsing an array", ), } } } impl Error for ArrayParseError {} impl From<&[u8]> for ArrayParseError { fn from(_value: &[u8]) -> Self { Self::Eof } } impl AtomicBase for [u8; N] { type AParseError = ArrayParseError; } impl ImplMode for [u8; N] { type Mode = InliningMode; } impl CInliningAtomic for [u8; N] { fn ca_extension_error(tail: &[u8]) -> Self::AParseError { ArrayParseError::ExtraData(tail.len()) } fn ca_ideserialize(stream: I) -> AIParseResult { stream.iread_n_const::(|slice| ArrayParseError::from(slice)) } } impl ConstSizeAtomic for [u8; N] { const SIZE: usize = N; }