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

Tracking Issue for box_vec_non_null #130364

Open
1 of 3 tasks
theemathas opened this issue Sep 14, 2024 · 1 comment
Open
1 of 3 tasks

Tracking Issue for box_vec_non_null #130364

theemathas opened this issue Sep 14, 2024 · 1 comment
Labels
C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@theemathas
Copy link
Contributor

theemathas commented Sep 14, 2024

Feature gate: #![feature(box_vec_non_null)]

This is a tracking issue for convenience methods for conversion between NonNull and Vec/Box.

Public API

impl<T: ?Sized> Box<T> {
    pub unsafe fn from_non_null(ptr: NonNull<T>) -> Self { .... }
}
impl<T: ?Sized, A: Allocator> Box<T, A> {
    pub const unsafe fn from_non_null_in(raw: NonNull<T>, alloc: A) -> Self { .... }
    pub fn into_non_null(b: Self) -> NonNull<T> { .... }
    pub fn into_non_null_with_allocator(b: Self) -> (NonNull<T>, A) { .... }
}
impl<T> Vec<T> {
    pub unsafe fn from_parts(ptr: NonNull<T>, length: usize, capacity: usize) -> Self { .... }
}
impl<T, A: Allocator> Vec<T, A> {
    pub unsafe fn from_parts_in(ptr: NonNull<T>, length: usize, capacity: usize, alloc: A) -> Self { .... }
    pub fn into_parts(self) -> (NonNull<T>, usize, usize) { .... }
    pub fn into_parts_with_alloc(self) -> (NonNull<T>, usize, usize, A) { .... }
    pub fn as_non_null(&mut self) -> NonNull<T> { .... }
}

Steps / History

Unresolved Questions

  • None yet.

Footnotes

  1. https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html

@theemathas theemathas added C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Sep 14, 2024
@scottmcm
Copy link
Member

scottmcm commented Sep 18, 2024

One thing I wanted to bring up here in terms of the "parts" name: I think from_parts is a great name, but I wonder if this is the right split to get that nice short name. Especially if we ever got another pointer type -- perhaps an aligned one -- it's not super-clear to me that NonNull is necessarily the right phrasing to get the shortest name.

Spitballing, what about something like this

impl<T, A> Vec<T, A> {
    pub const unsafe fn from_parts(buffer: Box<[MaybeUninit<T>], A>, initialized: RangeTo<usize>) -> Self;
    pub const fn into_parts(self) -> (Box<[MaybeUninit<T>], A>, RangeTo<usize>);
}

where it's no longer possible to accidentally get the capacity and length -- which have the same type, so the compiler doesn't help! -- in the wrong order. And the precondition for from_parts is simpler, because it only needs to talk about initializedness: everything about ownedness/readability/writability of the allocation comes from the Box. Could even have a safe version that takes the Box and gives a zero-length Vec, leaving it for you to set_len later to the initialized part, though I probably wouldn't want that as the only option.

And it doesn't need to have a separate function for an allocator-aware version because dealing in Box handles that.

GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Sep 20, 2024
…trieb

Add `Vec::as_non_null`

Implements the ACP: rust-lang/libs-team#440

The documentation is mostly copied from the existing `Vec::as_mut_ptr` method.

I am adding this method to the already-existing `box_vec_non_null` feature tracked at rust-lang#130364.
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Sep 20, 2024
Rollup merge of rust-lang#130624 - theemathas:vec_as_non_null, r=Noratrieb

Add `Vec::as_non_null`

Implements the ACP: rust-lang/libs-team#440

The documentation is mostly copied from the existing `Vec::as_mut_ptr` method.

I am adding this method to the already-existing `box_vec_non_null` feature tracked at rust-lang#130364.
RalfJung pushed a commit to RalfJung/miri that referenced this issue Sep 21, 2024
Add `Vec::as_non_null`

Implements the ACP: rust-lang/libs-team#440

The documentation is mostly copied from the existing `Vec::as_mut_ptr` method.

I am adding this method to the already-existing `box_vec_non_null` feature tracked at rust-lang/rust#130364.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

2 participants