File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -364,3 +364,30 @@ macro_rules! array_impl_default {
364
364
}
365
365
366
366
array_impl_default ! { 32 , T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T T }
367
+
368
+ #[ lang = "array" ]
369
+ #[ cfg( not( bootstrap) ) ]
370
+ impl < T , const N : usize > [ T ; N ] {
371
+ /// Returns an array of the same size as self, with `f` applied to each element.
372
+ ///
373
+ /// # Examples
374
+ /// ```
375
+ /// let x = [1,2,3];
376
+ /// let y = x.map(|v| v + 1);
377
+ /// assert_eq!(y, [2,3,4]);
378
+ /// ```
379
+ #[ unstable( feature = "array_map" , issue = "77777" ) ]
380
+ fn map < F , S > ( self , f : F ) -> [ S ; N ]
381
+ where
382
+ F : FnMut ( T ) -> S ,
383
+ {
384
+ use crate :: mem:: MaybeUninit ;
385
+ let dst = MaybeUninit :: uninit_array :: < N > ( ) ;
386
+ for ( i, e) in self . into_iter ( ) . enumerate ( ) {
387
+ dst[ i] = MaybeUninit :: new ( f ( e) ) ;
388
+ }
389
+ // FIXME convert to crate::mem::transmute when works with generics
390
+ // unsafe { crate::mem::transmute::<[MaybeUninit<S>; N], [S; N]>(dst) }
391
+ unsafe { ( & mut dst as * mut _ as * mut [ S ; N ] ) . read ( ) }
392
+ }
393
+ }
Original file line number Diff line number Diff line change @@ -157,6 +157,7 @@ language_item_table! {
157
157
BoolImplItem , sym:: bool , bool_impl, Target :: Impl ;
158
158
CharImplItem , sym:: char , char_impl, Target :: Impl ;
159
159
StrImplItem , sym:: str , str_impl, Target :: Impl ;
160
+ ArrayImplItem , sym:: array, array_impl, Target :: Impl ;
160
161
SliceImplItem , sym:: slice, slice_impl, Target :: Impl ;
161
162
SliceU8ImplItem , sym:: slice_u8, slice_u8_impl, Target :: Impl ;
162
163
StrAllocImplItem , sym:: str_alloc, str_alloc_impl, Target :: Impl ;
You can’t perform that action at this time.
0 commit comments