mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 16:24:46 +00:00
Rollup merge of #71165 - lcnr:patch-2, r=Amanieu
`slice::fill`: use `T` instead of generic arg implements https://github.com/rust-lang/rust/issues/70758#issuecomment-613994427 As the discussion in #70758 has shifted, I now use `T` instead of `&T`.
This commit is contained in:
commit
8cb8d9cfe2
@ -23,7 +23,6 @@
|
||||
// * The `raw` and `bytes` submodules.
|
||||
// * Boilerplate trait implementations.
|
||||
|
||||
use crate::borrow::Borrow;
|
||||
use crate::cmp;
|
||||
use crate::cmp::Ordering::{self, Equal, Greater, Less};
|
||||
use crate::fmt;
|
||||
@ -2157,14 +2156,16 @@ impl<T> [T] {
|
||||
/// assert_eq!(buf, vec![1; 10]);
|
||||
/// ```
|
||||
#[unstable(feature = "slice_fill", issue = "70758")]
|
||||
pub fn fill<V>(&mut self, value: V)
|
||||
pub fn fill(&mut self, value: T)
|
||||
where
|
||||
V: Borrow<T>,
|
||||
T: Clone,
|
||||
{
|
||||
let value = value.borrow();
|
||||
for el in self {
|
||||
el.clone_from(value)
|
||||
if let Some((last, elems)) = self.split_last_mut() {
|
||||
for el in elems {
|
||||
el.clone_from(&value);
|
||||
}
|
||||
|
||||
*last = value
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user