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.
|
// * The `raw` and `bytes` submodules.
|
||||||
// * Boilerplate trait implementations.
|
// * Boilerplate trait implementations.
|
||||||
|
|
||||||
use crate::borrow::Borrow;
|
|
||||||
use crate::cmp;
|
use crate::cmp;
|
||||||
use crate::cmp::Ordering::{self, Equal, Greater, Less};
|
use crate::cmp::Ordering::{self, Equal, Greater, Less};
|
||||||
use crate::fmt;
|
use crate::fmt;
|
||||||
@ -2157,14 +2156,16 @@ impl<T> [T] {
|
|||||||
/// assert_eq!(buf, vec![1; 10]);
|
/// assert_eq!(buf, vec![1; 10]);
|
||||||
/// ```
|
/// ```
|
||||||
#[unstable(feature = "slice_fill", issue = "70758")]
|
#[unstable(feature = "slice_fill", issue = "70758")]
|
||||||
pub fn fill<V>(&mut self, value: V)
|
pub fn fill(&mut self, value: T)
|
||||||
where
|
where
|
||||||
V: Borrow<T>,
|
|
||||||
T: Clone,
|
T: Clone,
|
||||||
{
|
{
|
||||||
let value = value.borrow();
|
if let Some((last, elems)) = self.split_last_mut() {
|
||||||
for el in self {
|
for el in elems {
|
||||||
el.clone_from(value)
|
el.clone_from(&value);
|
||||||
|
}
|
||||||
|
|
||||||
|
*last = value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user