diff options
| author | bors <bors@rust-lang.org> | 2020-04-05 06:22:35 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2020-04-05 06:22:35 +0000 |
| commit | 7b657d340d715f48449189fea9d032350323a13f (patch) | |
| tree | 1b090e20669f59fc9fafd1a0a1e1bdf09082597e /src/libcore | |
| parent | e129923b7e4d58a92c8a0530cd6eaa5be548342d (diff) | |
| parent | 5c42fafaf9823d284917d64c18d5e98d5d705888 (diff) | |
Auto merge of #70800 - Dylan-DPC:rollup-9jjoptp, r=Dylan-DPC
Rollup of 6 pull requests Successful merges: - #70635 (rustc_target: Some cleanup to `no_default_libraries`) - #70748 (Do not disable field reordering on enums with big discriminant) - #70752 (Add slice::fill) - #70766 (use ManuallyDrop instead of forget inside collections) - #70768 (macro_rules: `NtLifetime` cannot start with an identifier) - #70783 (comment refers to removed type) Failed merges: r? @ghost
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/slice/mod.rs | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/libcore/slice/mod.rs b/src/libcore/slice/mod.rs index 9be52e2dfb0..66aad324618 100644 --- a/src/libcore/slice/mod.rs +++ b/src/libcore/slice/mod.rs @@ -23,6 +23,7 @@ // * 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; @@ -2145,6 +2146,29 @@ impl<T> [T] { } } + /// Fills `self` with elements by cloning `value`. + /// + /// # Examples + /// + /// ``` + /// #![feature(slice_fill)] + /// + /// let mut buf = vec![0; 10]; + /// buf.fill(1); + /// assert_eq!(buf, vec![1; 10]); + /// ``` + #[unstable(feature = "slice_fill", issue = "70758")] + pub fn fill<V>(&mut self, value: V) + where + V: Borrow<T>, + T: Clone, + { + let value = value.borrow(); + for el in self { + el.clone_from(value) + } + } + /// Copies the elements from `src` into `self`. /// /// The length of `src` must be the same as `self`. |
