@@ -1345,6 +1345,25 @@ where
13451345 }
13461346}
13471347
1348+ #[ cfg( all( has_std, rustc_1_51) ) ]
1349+ impl < K , V , const N : usize > From < [ ( K , V ) ; N ] > for IndexMap < K , V , RandomState >
1350+ where
1351+ K : Hash + Eq ,
1352+ {
1353+ /// # Examples
1354+ ///
1355+ /// ```
1356+ /// use indexmap::IndexMap;
1357+ ///
1358+ /// let map1 = IndexMap::from([(1, 2), (3, 4)]);
1359+ /// let map2: IndexMap<_, _> = [(1, 2), (3, 4)].into();
1360+ /// assert_eq!(map1, map2);
1361+ /// ```
1362+ fn from ( arr : [ ( K , V ) ; N ] ) -> Self {
1363+ std:: array:: IntoIter :: new ( arr) . collect ( )
1364+ }
1365+ }
1366+
13481367impl < K , V , S > Extend < ( K , V ) > for IndexMap < K , V , S >
13491368where
13501369 K : Hash + Eq ,
@@ -1839,4 +1858,15 @@ mod tests {
18391858 assert ! ( values. contains( & 'b' ) ) ;
18401859 assert ! ( values. contains( & 'c' ) ) ;
18411860 }
1861+
1862+ #[ test]
1863+ #[ cfg( all( has_std, rustc_1_51) ) ]
1864+ fn from_array ( ) {
1865+ let map = IndexMap :: from ( [ ( 1 , 2 ) , ( 3 , 4 ) ] ) ;
1866+ let mut expected = IndexMap :: new ( ) ;
1867+ expected. insert ( 1 , 2 ) ;
1868+ expected. insert ( 3 , 4 ) ;
1869+
1870+ assert_eq ! ( map, expected)
1871+ }
18421872}
0 commit comments