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 [T; N]::as_[mut_]slice #76120

Merged
merged 2 commits into from
Sep 3, 2020

Conversation

LukasKalbertodt
Copy link
Member

Part of me trying to populate arrays with a couple of basic useful methods, like slices already have. The ability to add methods to arrays were added in #75212. Tracking issue: #76118

This adds:

impl<T, const N: usize> [T; N] {
    pub fn as_slice(&self) -> &[T];
    pub fn as_mut_slice(&mut self) -> &mut [T];
}

These methods are like the ones on std::array::FixedSizeArray and in the crate arraytools.

These methods are like the ones on `std::array::FixedSizeArray`
and in the crate `arraytools`.
@rust-highfive
Copy link
Collaborator

r? @Mark-Simulacrum

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 30, 2020
@joshtriplett
Copy link
Member

I've wanted these methods several times. Thanks!

@Mark-Simulacrum
Copy link
Member

r=me on implementation, since you are a libs team member :)

It does feel a bit awkward to have these, since you get the same behavior just from coercion... but triggering coercion can be painful, and often means falling back on slicing, so this seems reasonable.

@scottmcm
Copy link
Member

scottmcm commented Sep 2, 2020

Given that Vec has these, it makes sense that arrays might as well too.

Hmm, it looks like this obviates FixedSizeArray -- could that just be removed entirely, now?

@LukasKalbertodt
Copy link
Member Author

r=me on implementation, since you are a libs team member :)

Mhhhh... I'm not exactly sure what that means :D are you saying I can merge at my own convenience with r=Mark-Simulacrum?

Hmm, it looks like this obviates FixedSizeArray -- could that just be removed entirely, now?

Probably? Though I would not include its removal in this PR. We might also want to wait a cycle or so before removing it.

@Mark-Simulacrum
Copy link
Member

I mean that we normally need libs sign off on unstable API but you can self grant that and the impl looks good, so yes, just r=me when ready.

@LukasKalbertodt
Copy link
Member Author

From my side, this is ready. Let's merge it then, it's only unstable anyway.

@bors r=Mark-Simulacrum

@bors
Copy link
Contributor

bors commented Sep 2, 2020

📌 Commit d7afe2a has been approved by Mark-Simulacrum

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 2, 2020
@bors
Copy link
Contributor

bors commented Sep 3, 2020

⌛ Testing commit d7afe2a with merge 8247a30061a79a7923718edf5a68d8eac473ee00...

@Dylan-DPC-zz
Copy link

@bors retry yield

bors added a commit to rust-lang-ci/rust that referenced this pull request Sep 3, 2020
Rollup of 12 pull requests

Successful merges:

 - rust-lang#75150 (Add a note for Ipv4Addr::to_ipv6_compatible)
 - rust-lang#76120 (Add `[T; N]::as_[mut_]slice`)
 - rust-lang#76142 (Make all methods of `std::net::Ipv4Addr` const)
 - rust-lang#76164 (Link to slice pattern in array docs)
 - rust-lang#76167 (Replace MinGW library hack with heuristic controlling link mode)
 - rust-lang#76204 (Rename and expose LoopState as ControlFlow)
 - rust-lang#76238 (Move to intra-doc links for library/core/src/iter/traits/iterator.rs)
 - rust-lang#76242 (Read: adjust a FIXME reference)
 - rust-lang#76243 (Fix typos in vec try_reserve(_exact) docs)
 - rust-lang#76245 (inliner: Avoid query cycles when optimizing generators)
 - rust-lang#76255 (Update books)
 - rust-lang#76261 (Use intra-doc links in `core::marker`)

Failed merges:

r? @ghost
@bors bors merged commit 10aa3d3 into rust-lang:master Sep 3, 2020
@LukasKalbertodt LukasKalbertodt deleted the add-as-slice-method-to-array branch September 3, 2020 06:43
jethrogb pushed a commit to jethrogb/rust that referenced this pull request Sep 14, 2020
@jethrogb jethrogb mentioned this pull request Sep 14, 2020
@cuviper cuviper added this to the 1.48.0 milestone Nov 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants