diff options
| author | Bastian Kauschke <bastian_kauschke@hotmail.de> | 2020-04-16 17:49:41 +0200 |
|---|---|---|
| committer | Bastian Kauschke <bastian_kauschke@hotmail.de> | 2020-05-02 20:15:05 +0200 |
| commit | 902aa62d51210403787f54b881918319e51866c2 (patch) | |
| tree | 4ce5c460f7583b2b64da18ab0bef0a555c79c430 /src/libcore | |
| parent | 7184d137f65bb8d143ce8b5b664e50d33c4b5fbd (diff) | |
| download | rust-902aa62d51210403787f54b881918319e51866c2.tar.gz rust-902aa62d51210403787f54b881918319e51866c2.zip | |
slice::fill: take T by value.
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/slice/mod.rs | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/src/libcore/slice/mod.rs b/src/libcore/slice/mod.rs index 7b357bb487a..f74c6862006 100644 --- a/src/libcore/slice/mod.rs +++ b/src/libcore/slice/mod.rs @@ -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 } } |
