Skip to content

Support uninitialized caller output buffers (MaybeUninit<u8>) #11

Closed

Description

@tisonkun

Context

All internal backends in bases already write directly into &mut [MaybeUninit<u8>], avoiding redundant zero-fills in encode, decode, and decode_array. However, the public caller-buffer methods encode_into and decode_into in bases/src/codec.rs still require an initialized &mut [u8], forcing stack-buffer callers ([0_u8; N]) to zero-initialize memory upfront and preventing direct zero-copy writes into Vec::spare_capacity_mut() or BytesMut::spare_capacity_mut().

Considerations

  • Without introducing external dependencies such as outref, compare adding explicit encode_into_uninit and decode_into_uninit methods (returning initialized &mut str and &mut [u8]) against providing a minimal zero-dependency output buffer wrapper that accepts both &mut [u8] and &mut [MaybeUninit<u8>].
  • Check whether Encoder::update / finish and Decoder::update / finish should mirror the same choice or keep slice APIs minimal.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions