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 resize(_with) and (try_)repeat(_with) for arrays #91506

Closed
wants to merge 2 commits into from

Commits on Dec 6, 2021

  1. Add repeat and resize(_with) for arrays

    ```rust
    mod array {
        pub fn repeat<T: Clone, const N: usize>(value: T) -> [T; N];
    }
    
    impl [T; N] {
        pub fn resize<const NEW_LEN: usize>(self, value: T) -> [T; NEW_LEN] where T: Clone;
        pub fn resize_with<const NEW_LEN: usize>(self, mut f: impl FnMut() -> T) -> [T; NEW_LEN];
    }
    ```
    
    I tried to do `resize_with` as just
    ```rust
    collect_into_array(IntoIter::new(self).chain(iter::repeat_with(f)))
    ```
    but unfortunately that optimized very poorly.
    
    As a result there's a bunch of refactoring in here to move the `Guard` struct that was previously private to `try_collect_into_array` over to its own module.  It's still very much internal -- it's visible only to the `core::array` module, with no intention of making this the anointed public thing.
    scottmcm committed Dec 6, 2021
    Configuration menu
    Copy the full SHA
    5a784e6 View commit details
    Browse the repository at this point in the history

Commits on Dec 7, 2021

  1. Configuration menu
    Copy the full SHA
    5c09e1a View commit details
    Browse the repository at this point in the history