File tree 1 file changed +24
-0
lines changed
1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change 23
23
// * The `raw` and `bytes` submodules.
24
24
// * Boilerplate trait implementations.
25
25
26
+ use crate :: borrow:: Borrow ;
26
27
use crate :: cmp;
27
28
use crate :: cmp:: Ordering :: { self , Equal , Greater , Less } ;
28
29
use crate :: fmt;
@@ -2145,6 +2146,29 @@ impl<T> [T] {
2145
2146
}
2146
2147
}
2147
2148
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
+
2148
2172
/// Copies the elements from `src` into `self`.
2149
2173
///
2150
2174
/// The length of `src` must be the same as `self`.
You can’t perform that action at this time.
0 commit comments