Description
In the light of aiming for a stabilized API of v1.0 (#410) but having just done a significant API changeset in 0.8, I wanted to bring something up that has been bugging me several times.
Currently the heapless::Vec
API is significantly different from both std::Vec
and alternative no_std/no-alloc Vec
implementations like tinyvec::ArrayVec
or arrayvec::ArrayVec
or coca. This is especially true for the important case where std::Vec
would reallocate but its fixed size alternatives must either panic or become fallible: e.g. Vec::push()
.
heapless
deviates from the others in its API and makes these fallible. The others are panicing and additionally/alternatively tend to offer a fallible API (ArrayVec::try_push()
).
IMO it would be nice if we could overall
- align the API with the
std::Vec
API andtinyvec
- offer a fallible API (
try_push()
etc).
That would make porting a bit easier. And it could allow heapless::Vec
to be a drop-in replacement for tinyvec::ArrayVec
. The only (AFAICT) remaining difference would be under the hood: the use of MaybeUninit
.
The API difference comes up from time tom time e.g. #440.
There is demand for distinct operations that are both infallible and non-panicing: #341
There may also be other places in heapless
where the API choice diverges from the std
analogue.