-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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 the slice::fill method #70758
Comments
If nothing else, it feels a little weird that this is in reverse of how the maps and sets use |
I don't like the trait bound
(std) |
+1 for taking a
This reads like a template meant for "large" language features and doesn’t seem to really apply here. There is not a github label for every single unstable library feature. |
This does make the common case somewhat awkward: let mut buf = vec![0; 10];
buf.fill(1); // compiler error!
buf.fill(&1); // ok
assert_eq!(buf, vec![1; 10]); Understanding why a let mut buf = vec![0; 10];
buf.fill(1); // ok
buf.fill(&1); // ok
assert_eq!(buf, vec![1; 10]); An alternative would be to always take-by-value, allowing it to be worked around by calling let mut buf = ...;
let my_t = ...;
buf.fill(my_t.clone());
// my_t is still available here However this also seems somewhat awkward given that the type already implements |
Using
When filling a slice of if let Some((start, rest)) = slice.split_first_mut() {
for el in rest {
el.clone_from(&value)
}
*start = value;
} |
We should consider that this is exactly what "discarding ownership" is intended to address. Rather than being super generic as Simon pointed out this can damage type inference, there's nothing wrong with allowing |
FWIW, this is true of slice |
Consistency with |
|
The motivation for having |
What would be the advantage to taking |
|
Without something like "discarding ownership" you would have to manually reference it instead.
With by-value we could avoid an extra clone in the likely common case where you no longer need the value and the slice isn't empty. As far as consistency is concerned |
FWIW, I'm not firm on it being |
`slice::fill`: use `T` instead of generic arg implements rust-lang#70758 (comment) As the discussion in rust-lang#70758 has shifted, I now use `T` instead of `&T`.
`slice::fill`: use `T` instead of generic arg implements rust-lang#70758 (comment) As the discussion in rust-lang#70758 has shifted, I now use `T` instead of `&T`.
Since |
@m-ou-se I think that's a reasonable addition; though it could be useful to track separately so we can stabilize the two functions independently? |
Sure. Just mentioning it here because |
I think |
Add `core::slice::fill_with` Tracking issue rust-lang#79221. As suggested by `@m-ou-se` in rust-lang#70758 (comment) this implements `slice::fill_with` as a counterpart to `slice::fill`. This mirrors `Vec::resize` and `Vec::resize_with`. Thanks! r? `@m-ou-se`
Add `core::slice::fill_with` Tracking issue rust-lang#79221. As suggested by `@m-ou-se` in rust-lang#70758 (comment) this implements `slice::fill_with` as a counterpart to `slice::fill`. This mirrors `Vec::resize` and `Vec::resize_with`. Thanks! r? `@m-ou-se`
…=m-ou-se Stabilize `core::slice::fill` Tracking issue rust-lang#70758 Stabilizes the `core::slice::fill` API in Rust 1.50, adding a `memset` doc alias so people coming from C/C++ looking for this operation can find it in the docs. This API hasn't seen any changes since we changed the signature in rust-lang#71165, and it seems like the right time to propose stabilization. Thanks! r? `@m-ou-se`
…=m-ou-se Stabilize `core::slice::fill` Tracking issue rust-lang#70758 Stabilizes the `core::slice::fill` API in Rust 1.50, adding a `memset` doc alias so people coming from C/C++ looking for this operation can find it in the docs. This API hasn't seen any changes since we changed the signature in rust-lang#71165, and it seems like the right time to propose stabilization. Thanks! r? ``@m-ou-se``
…=m-ou-se Stabilize `core::slice::fill` Tracking issue rust-lang#70758 Stabilizes the `core::slice::fill` API in Rust 1.50, adding a `memset` doc alias so people coming from C/C++ looking for this operation can find it in the docs. This API hasn't seen any changes since we changed the signature in rust-lang#71165, and it seems like the right time to propose stabilization. Thanks! r? `@m-ou-se`
Closing as the PR has been merged and stabilized for Rust 1.50 |
This is a tracking issue for the
slice::fill
method.The feature gate for the issue is
#![feature(slice_fill)]
.About tracking issues
Tracking issues are used to record the overall progress of implementation.
They are also uses as hubs connecting to other relevant issues, e.g., bugs or open design questions.
A tracking issue is however not meant for large scale discussion, questions, or bug reports about a feature.
Instead, open a dedicated issue for the specific matter and add the relevant feature gate label.
Steps
Unresolved Questions
V: Borrow<T>
the most appropriate bound for the argument?Implementation history
slice::fill
: useT
instead of generic arg #71165core::slice::fill
#79213The text was updated successfully, but these errors were encountered: