-
Notifications
You must be signed in to change notification settings - Fork 13.9k
Add resize(_with) and (try_)repeat(_with) for arrays
#91506
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
Conversation
|
r? @m-ou-se (rust-highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
e66d013 to
019e0e8
Compare
This comment has been minimized.
This comment has been minimized.
019e0e8 to
e6a38eb
Compare
This comment has been minimized.
This comment has been minimized.
```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.
e6a38eb to
5a784e6
Compare
repeat and resize(_with) for arraysresize(_with) and (try_)repeat(_with) for arrays
|
I added |
|
@m-ou-se Friendly ping for the new year. |
|
As you said, For |
|
This is going to bit-rot soon from conflicts, so I'll just close it. |
I tried to do
resize_withas justbut unfortunately that optimized very poorly.
As a result there's a bunch of refactoring in here to move the
Guardstruct that was previously private totry_collect_into_arrayover to its own module. It's still very much internal -- it's visible only to thecore::arraymodule, with no intention of making it the anointed public thing. (And thus it basically only has_uncheckedmethods.)This comes with codegen tests, so preemptively
@bors rollup=iffy