Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add helper functions for Array<MaybeUninit<T>, U> #8

Merged
merged 4 commits into from
Jan 11, 2024

Conversation

tarcieri
Copy link
Member

Adds the following functions:

  • uninit: construct an uninitialized Array<MaybeUninit<T>, U>
  • assume_init: converts to Array<T, U> assuming all elements are initialized

Adds the following functions:

- `uninit`: construct an uninitialized `Array<MaybeUninit<T>, U>`
- `assume_init`: converts to `Array<T, U>` assuming all elements are
  initialized
src/lib.rs Outdated Show resolved Hide resolved
Copy link
Member

@newpavlov newpavlov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be safe I think we should ask on IRLO about the uninit method, but AFAIK the code should be fine. It's worth to expand the safety comment and explicitly note that we "assume init" an array of MaybeUninits.

@tarcieri
Copy link
Member Author

Expanding the safety comment sounds good. I can also add a link to the similarly-shaped uninit_array method.

This makes the bounds more complicated but makes it much clearer what's
happening, as before it was relying on an implicit definition of
`ArraySize::ArrayType`.
@tarcieri
Copy link
Member Author

@newpavlov d7f32a4 should make it much more explicit what's happening (at the cost of slightly more complicated bounds), and also clears the clippy warning

@tarcieri
Copy link
Member Author

Seems at little closer to pub const fn assume_init too:

error[E0658]: cannot borrow here, since the borrowed element may contain interior mutability
   --> src/lib.rs:245:25
    |
245 |         Array(ptr::read(self.0.as_ptr().cast()))
    |                         ^^^^^^
    |
    = note: see issue #80384 <https://github.com/rust-lang/rust/issues/80384> for more information

@tarcieri tarcieri merged commit 1905e76 into master Jan 11, 2024
13 checks passed
@tarcieri tarcieri deleted the maybe-uninit-helpers branch January 11, 2024 21:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants