rust-lang / rust-lang/rust-bindgen

Provide safe allocation API for varsized structs

Open
#1,423 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement help wanted
Dominant language
Rust
Stars
5.3k
Forks
829
Avg merge
1d 1h
Merged PRs (30d)
15

Description

Currently if you have a varsized struct (struct { size_t length; uint64_t data[] };), you're responsible for figuring out how to allocate it yourself, which can be messy and unsafe.

Would it be reasonable for the generated Rust type for that struct to have an API for allocating it, with a certain length (NB, the user would still be responsible for filling in the length field)?

This would be beneficial by a) being more ergonomic, and more importantly b) consistently handling things like integer overflows to make code safer!

Contributor guide

Open the contributing guide

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

No file or test is identified in the issue. Start by locating the generated Rust representation for varsized C structs and any allocation-related tests, then clarify the intended length-based API and overflow behavior. Done means the generated type offers safe allocation for a requested length and the behavior is covered by tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, rust
Domain
devtools
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.