rust-embedded / rust-embedded/heapless

API alignment

Open
#442 19 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Rust
Stars
2k
Forks
253
Avg merge
1d 2h
Merged PRs (30d)
1

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 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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by comparing the heapless::Vec API with std::Vec, tinyvec::ArrayVec, and arrayvec::ArrayVec, then read the discussion in issues #410, #440, and #341. Done means the project has an agreed v1.0 API direction covering std-like operations and fallible alternatives such as try_push().

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
backend-api-design
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.