Skip to content

Request for feature: unsafe as a qualifier for structure fields #8409

Closed
@mstewartgallus

Description

@mstewartgallus

When wrapping low-level, and unsafe APIs like OpenGL ES there is often a need to provide fallbacks to unsafety. Currently, one has to create private fields, and a large amount of ugly conversion functions in the style of unsafe fn raw_handle(&self)->gl::GLuint, and unsafe fn from_raw_handle(gl::GLuint)->Attribute<State, T>. I would prefer not to.

The best existing workaround would probable be to generate these conversion functions using a macro that would be used like unsafe_field!(raw_handle, Attribute<State, T>). I am not sure how best to create such a macro though.

I feel a nice solution to this problem would be the ability to tag structure fields with the unsafe keyword so that they could only be accessed within an unsafe block.

The syntax pub struct Attribute<'self, S, T> { unsafe context: &'self Context, unsafe contents: gl::GLuint } seems intuitive to me but does not generalize nicely to enumerations, or tuple structs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions