Skip to content

API alignment #442

Open
Open
@jordens

Description

@jordens

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 and tinyvec
  • 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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions