Can we use non_exhausive attr instead of zero length array in "Representing Opaque Structs"
Nobody has claimed this yet.
- Dominant language
- CSS
- Stars
- 2.3k
- Forks
- 325
- PR merge metrics
- No merged PRs in 30d
Description
Section: https://doc.rust-lang.org/nomicon/ffi.html#representing-opaque-structs
Currently, it uses a struct like this:
#[repr(C)]
pub struct Foo {
_data: [u8; 0],
_marker:
core::marker::PhantomData<(*mut u8, core::marker::PhantomPinned)>,
}
But since that was written, we have access to the #[non_exhausive] attribute. I think it has the same functionality. Any reason we shouldn't be suggesting this instead?
#[repr(C)]
#[non_exhaustive]
pub struct Foo {
_marker:
core::marker::PhantomData<(*mut u8, core::marker::PhantomPinned)>,
}
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the “Representing Opaque Structs” section in doc.rust-lang.org/nomicon/ffi.html and compare the documented zero-length-array pattern with the proposed #[non_exhaustive] form. Verify whether the attribute provides the same FFI and opacity guarantees, then update the section if appropriate and document any reason to retain the existing pattern.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100