On Fri Oct 16, 2026 at 10:53 AM JST, Eliot Courtney wrote: > Similar to the typed encoding layer, add some decoding type machinery. > Add a simple macro `nvkv_decode!` which implements `Schema` for a struct > by composing visit calls to each member. Add some common `Schema` kinds, > such as `Array` which collects an array value into a fixed maximum size > array, and `Required` which fails a decode if the value is not sent. > > Signed-off-by: Eliot Courtney <[email protected]>
Reviewed-by: Alexandre Courbot <[email protected]> A few (hopefully final) nits below. <...> > +impl<T: Default, const KEY_ID: KeyId, As> Schema for Key<T, KEY_ID, As> { > + type Target = T; > + > + fn init() -> impl Init<Self> { > + Self::default() > + } > + > + fn finish(&mut self) -> impl Init<Self::Target, Error> + '_ { > + const_assert!( > + size_of::<T>() <= 32, Let's use a constant here again instead of a hardcoded value. We could share that constant with `Encodable::encode`. <...> > +/// A schema field for an array value under the NVKV key `KEY_ID` that keeps > at most `N` elements. > +/// > +/// Unlike [`Array`], a longer value is truncated to its first `N` elements > instead of failing the > +/// decode. > +pub(crate) struct TruncatingArray<T, const N: usize, const KEY_ID: KeyId> { > + vec: ArrayVec<T, N>, > +} This is basically a copy/paste of `Array`, with one line changing in `visit`. Is it possible to just wrap `Array`, proxy the methods that are identical, and only duplicate `visit`? (or better, have a private function in `Array` that is called by both `visit` implementations to reduce code duplication even more)
