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 @@ -3059,6 +3059,30 @@ impl<T> [T] {
3059
3059
3060
3060
left
3061
3061
}
3062
+
3063
+ /// Moves `value` into `self[index]`, returning the old value.
3064
+ ///
3065
+ /// Neither value is dropped.
3066
+ ///
3067
+ /// # Panics
3068
+ ///
3069
+ /// Panics if `index` is out of bounds.
3070
+ ///
3071
+ /// # Examples
3072
+ ///
3073
+ /// ```
3074
+ /// #![feature(slice_replace)]
3075
+ ///
3076
+ /// let mut v = [1, 2, 3];
3077
+ /// let r = v.replace(1, 20);
3078
+ ///
3079
+ /// assert_eq!(v, [1, 20, 3]);
3080
+ /// assert_eq!(r, 2);
3081
+ /// ```
3082
+ #[ unstable( feature = "slice_replace" , reason = "new API" , issue = "none" ) ]
3083
+ pub fn replace ( & mut self , index : usize , value : T ) -> T {
3084
+ mem:: replace ( & mut self [ index] , value)
3085
+ }
3062
3086
}
3063
3087
3064
3088
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
You can’t perform that action at this time.
0 commit comments