rust-lang / rust-lang/rfcs

Idea: Opaque, repr(transparent) C types

Open
#2,601 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-ffi A-types-libstd T-libs
Dominant language
Markdown
Stars
6.6k
Forks
1.7k
Avg merge
16h 14m
Merged PRs (30d)
1

Description

Essentially, replace the types in os::raw with new versions in core::ffi which are opaque, repr(transparent) types. This allows us to add, e.g. a c_longdouble which does not necessarily map to a native Rust type.

Conversion to/from these types should be done using From and TryFrom, where From is only implemented strictly according to the C spec (e.g. From<u32> is not implemented for c_uint, but From<u16> is). For floats, conversions would probably not be done by From and TryFrom, but that can be fleshed out later; adding just the integer types for now would be very nice.

Not 100% sure whether these types should implement basic arithmetic operations or methods representing functions from C math, but that's my basic idea right now.

c_void is already in core::ffi, so, these types would be joining it.

I've had ideas for drafting an RFC for this but I doubt I'll have the energy any time soon, so, I figured I'd offer the idea here if anyone wants to take it up.

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 reviewing the existing types in os::raw and core::ffi::c_void. Work through the proposed opaque repr(transparent) integer types, their From and TryFrom rules, and the unresolved arithmetic and floating-point questions. Done means the design is sufficiently settled for an RFC or implementation plan.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
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.