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 option_array_transpose #130828

Open
1 of 3 tasks
Urgau opened this issue Sep 25, 2024 · 4 comments
Open
1 of 3 tasks

Tracking Issue for option_array_transpose #130828

Urgau opened this issue Sep 25, 2024 · 4 comments
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

@Urgau
Copy link
Member

Urgau commented Sep 25, 2024

Feature gate: #![feature(option_array_transpose)]

This is a tracking issue for the option_array_transpose.

This feature permits going from an [Option<T>; N] to Option<[T; N]>.

Public API

// core::option

impl<T, const N: usize> [Option<T>; N] {
    fn transpose(self) -> Option<[T; N]>;
}

Steps / History

Unresolved Questions

Footnotes

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

@Urgau Urgau 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 25, 2024
@tgross35
Copy link
Contributor

Should there be something similar for the other way, Option<[T; N]> -> [Option<T>; N]?

@Nemo157
Copy link
Member

Nemo157 commented Sep 26, 2024

This doesn't feel like a "transpose" operation to me, afaik all existing transpose methods are information-preserving, they only affect the type system, this one allows [None, Some(1)] -> None destroying the information that some elements were not None.

@Urgau
Copy link
Member Author

Urgau commented Sep 26, 2024

@Nemo157 Look at [MaybeUninit<T>; N]::transpose for a precedent.

@Nemo157
Copy link
Member

Nemo157 commented Sep 26, 2024

That also doesn't destroy any runtime data, you can array_of_maybe_uninit.transpose().transpose() and get back the same value.

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

3 participants