File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -2599,6 +2599,34 @@ impl<T> [T] {
25992599 }
26002600 }
26012601
2602+ /// Fills `self` with elements returned by calling a closure repeatedly.
2603+ ///
2604+ /// This method uses a closure to create new values. If you'd rather
2605+ /// [`Clone`] a given value, use [`fill`]. If you want to use the [`Default`]
2606+ /// trait to generate values, you can pass [`Default::default`] as the
2607+ /// argument.
2608+ ///
2609+ /// [`fill`]: #method.fill
2610+ ///
2611+ /// # Examples
2612+ ///
2613+ /// ```
2614+ /// #![feature(slice_fill_with)]
2615+ ///
2616+ /// let mut buf = vec![1; 10];
2617+ /// buf.fill_with(Default::default);
2618+ /// assert_eq!(buf, vec![0; 10]);
2619+ /// ```
2620+ #[ unstable( feature = "slice_fill_with" , issue = "79221" ) ]
2621+ pub fn fill_with < F > ( & mut self , mut f : F )
2622+ where
2623+ F : FnMut ( ) -> T ,
2624+ {
2625+ for el in self {
2626+ * el = f ( ) ;
2627+ }
2628+ }
2629+
26022630 /// Copies the elements from `src` into `self`.
26032631 ///
26042632 /// The length of `src` must be the same as `self`.
You can’t perform that action at this time.
0 commit comments