diff --git a/crates/stef/src/buf/decode.rs b/crates/stef/src/buf/decode.rs index 0e35f92..a09f655 100644 --- a/crates/stef/src/buf/decode.rs +++ b/crates/stef/src/buf/decode.rs @@ -19,6 +19,7 @@ pub enum Error { NonUtf8(std::string::FromUtf8Error), MissingField { id: u32, name: Option<&'static str> }, UnknownVariant(u32), + Zero, } impl From for Error { @@ -273,9 +274,24 @@ where } } -// ----------------------------- -// TODO: NonZero -// ----------------------------- +macro_rules! non_zero { + ($ty:ty) => { + paste::paste! { + impl Decode for std::num::[] { + #[inline(always)] + fn decode(r: &mut impl Buf) -> Result { + Self::new([](r)?).ok_or_else(|| Error::Zero) + } + } + } + }; + ($($ty:ty),+ $(,)?) => { + $(non_zero!($ty);)+ + }; +} + +non_zero!(u8, u16, u32, u64, u128); +non_zero!(i8, i16, i32, i64, i128); impl<'a, T> Decode for std::borrow::Cow<'a, T> where