File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change 2323// * The `raw` and `bytes` submodules.
2424// * Boilerplate trait implementations.
2525
26+ use crate :: borrow:: Borrow ;
2627use crate :: cmp;
2728use crate :: cmp:: Ordering :: { self , Equal , Greater , Less } ;
2829use crate :: fmt;
@@ -2145,6 +2146,29 @@ impl<T> [T] {
21452146 }
21462147 }
21472148
2149+ /// Fills `self` with elements by cloning `value`.
2150+ ///
2151+ /// # Examples
2152+ ///
2153+ /// ```
2154+ /// #![feature(slice_fill)]
2155+ ///
2156+ /// let mut buf = vec![0; 10];
2157+ /// buf.fill(1);
2158+ /// assert_eq!(buf, vec![1; 10]);
2159+ /// ```
2160+ #[ unstable( feature = "slice_fill" , issue = "70758" ) ]
2161+ pub fn fill < V > ( & mut self , value : V )
2162+ where
2163+ V : Borrow < T > ,
2164+ T : Clone ,
2165+ {
2166+ let value = value. borrow ( ) ;
2167+ for el in self {
2168+ el. clone_from ( value)
2169+ }
2170+ }
2171+
21482172 /// Copies the elements from `src` into `self`.
21492173 ///
21502174 /// The length of `src` must be the same as `self`.
You can’t perform that action at this time.
0 commit comments