Skip to content

Idea: Opaque, repr(transparent) C types #2601

Open
@clarfonthey

Description

@clarfonthey

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ffiFFI related proposals.A-types-libstdProposals & ideas introducing new types to the standard library.T-libs-apiRelevant to the library API team, which will review and decide on the RFC.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions