@@ -1024,6 +1024,16 @@ where
1024
1024
}
1025
1025
}
1026
1026
1027
+ // [B] == Vec<A, N>
1028
+ impl < A , B , const N : usize > PartialEq < Vec < A , N > > for [ B ]
1029
+ where
1030
+ A : PartialEq < B > ,
1031
+ {
1032
+ fn eq ( & self , other : & Vec < A , N > ) -> bool {
1033
+ <[ A ] >:: eq ( other, & self [ ..] )
1034
+ }
1035
+ }
1036
+
1027
1037
// Vec<A, N> == &[B]
1028
1038
impl < A , B , const N : usize > PartialEq < & [ B ] > for Vec < A , N >
1029
1039
where
@@ -1034,6 +1044,16 @@ where
1034
1044
}
1035
1045
}
1036
1046
1047
+ // &[B] == Vec<A, N>
1048
+ impl < A , B , const N : usize > PartialEq < Vec < A , N > > for & [ B ]
1049
+ where
1050
+ A : PartialEq < B > ,
1051
+ {
1052
+ fn eq ( & self , other : & Vec < A , N > ) -> bool {
1053
+ <[ A ] >:: eq ( other, & self [ ..] )
1054
+ }
1055
+ }
1056
+
1037
1057
// Vec<A, N> == &mut [B]
1038
1058
impl < A , B , const N : usize > PartialEq < & mut [ B ] > for Vec < A , N >
1039
1059
where
@@ -1044,6 +1064,16 @@ where
1044
1064
}
1045
1065
}
1046
1066
1067
+ // &mut [B] == Vec<A, N>
1068
+ impl < A , B , const N : usize > PartialEq < Vec < A , N > > for & mut [ B ]
1069
+ where
1070
+ A : PartialEq < B > ,
1071
+ {
1072
+ fn eq ( & self , other : & Vec < A , N > ) -> bool {
1073
+ <[ A ] >:: eq ( other, & self [ ..] )
1074
+ }
1075
+ }
1076
+
1047
1077
// Vec<A, N> == [B; M]
1048
1078
// Equality does not require equal capacity
1049
1079
impl < A , B , const N : usize , const M : usize > PartialEq < [ B ; M ] > for Vec < A , N >
@@ -1055,6 +1085,17 @@ where
1055
1085
}
1056
1086
}
1057
1087
1088
+ // [B; M] == Vec<A, N>
1089
+ // Equality does not require equal capacity
1090
+ impl < A , B , const N : usize , const M : usize > PartialEq < Vec < A , N > > for [ B ; M ]
1091
+ where
1092
+ A : PartialEq < B > ,
1093
+ {
1094
+ fn eq ( & self , other : & Vec < A , N > ) -> bool {
1095
+ <[ A ] >:: eq ( other, & self [ ..] )
1096
+ }
1097
+ }
1098
+
1058
1099
// Vec<A, N> == &[B; M]
1059
1100
// Equality does not require equal capacity
1060
1101
impl < A , B , const N : usize , const M : usize > PartialEq < & [ B ; M ] > for Vec < A , N >
@@ -1066,6 +1107,17 @@ where
1066
1107
}
1067
1108
}
1068
1109
1110
+ // &[B; M] == Vec<A, N>
1111
+ // Equality does not require equal capacity
1112
+ impl < A , B , const N : usize , const M : usize > PartialEq < Vec < A , N > > for & [ B ; M ]
1113
+ where
1114
+ A : PartialEq < B > ,
1115
+ {
1116
+ fn eq ( & self , other : & Vec < A , N > ) -> bool {
1117
+ <[ A ] >:: eq ( other, & self [ ..] )
1118
+ }
1119
+ }
1120
+
1069
1121
// Implements Eq if underlying data is Eq
1070
1122
impl < T , const N : usize > Eq for Vec < T , N > where T : Eq { }
1071
1123
@@ -1239,6 +1291,28 @@ mod tests {
1239
1291
assert ! ( xs < ys) ;
1240
1292
}
1241
1293
1294
+ #[ test]
1295
+ fn cmp_with_arrays_and_slices ( ) {
1296
+ let mut xs: Vec < i32 , 12 > = Vec :: new ( ) ;
1297
+ xs. push ( 1 ) . unwrap ( ) ;
1298
+
1299
+ let array = [ 1 ] ;
1300
+
1301
+ assert_eq ! ( xs, array) ;
1302
+ assert_eq ! ( array, xs) ;
1303
+
1304
+ assert_eq ! ( xs, array. as_slice( ) ) ;
1305
+ assert_eq ! ( array. as_slice( ) , xs) ;
1306
+
1307
+ assert_eq ! ( xs, & array) ;
1308
+ assert_eq ! ( & array, xs) ;
1309
+
1310
+ let longer_array = [ 1 ; 20 ] ;
1311
+
1312
+ assert_ne ! ( xs, longer_array) ;
1313
+ assert_ne ! ( longer_array, xs) ;
1314
+ }
1315
+
1242
1316
#[ test]
1243
1317
fn full ( ) {
1244
1318
let mut v: Vec < i32 , 4 > = Vec :: new ( ) ;
0 commit comments