Add slice::fill
This commit is contained in:
parent
f6fe99c798
commit
edabceb4a3
1 changed files with 24 additions and 0 deletions
|
@ -23,6 +23,7 @@
|
||||||
// * 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;
|
||||||
|
@ -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`.
|
/// Copies the elements from `src` into `self`.
|
||||||
///
|
///
|
||||||
/// The length of `src` must be the same as `self`.
|
/// The length of `src` must be the same as `self`.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue