@@ -832,28 +832,31 @@ move_index_oob!(test_move_index_out_of_bounds_max_0, usize::MAX, 0);
832
832
#[ test]
833
833
fn disjoint_mut_empty_map ( ) {
834
834
let mut map: IndexMap < u32 , u32 > = IndexMap :: default ( ) ;
835
- assert ! ( map. get_disjoint_mut( [ & 0 , & 1 , & 2 , & 3 ] ) . is_none( ) ) ;
835
+ assert_eq ! (
836
+ map. get_disjoint_mut( [ & 0 , & 1 , & 2 , & 3 ] ) ,
837
+ [ None , None , None , None ]
838
+ ) ;
836
839
}
837
840
838
841
#[ test]
839
842
fn disjoint_mut_empty_param ( ) {
840
843
let mut map: IndexMap < u32 , u32 > = IndexMap :: default ( ) ;
841
844
map. insert ( 1 , 10 ) ;
842
- assert ! ( map. get_disjoint_mut( [ ] as [ & u32 ; 0 ] ) . is_some ( ) ) ;
845
+ assert_eq ! ( map. get_disjoint_mut( [ ] as [ & u32 ; 0 ] ) , [ ] ) ;
843
846
}
844
847
845
848
#[ test]
846
849
fn disjoint_mut_single_fail ( ) {
847
850
let mut map: IndexMap < u32 , u32 > = IndexMap :: default ( ) ;
848
851
map. insert ( 1 , 10 ) ;
849
- assert ! ( map. get_disjoint_mut( [ & 0 ] ) . is_none ( ) ) ;
852
+ assert_eq ! ( map. get_disjoint_mut( [ & 0 ] ) , [ None ] ) ;
850
853
}
851
854
852
855
#[ test]
853
856
fn disjoint_mut_single_success ( ) {
854
857
let mut map: IndexMap < u32 , u32 > = IndexMap :: default ( ) ;
855
858
map. insert ( 1 , 10 ) ;
856
- assert_eq ! ( map. get_disjoint_mut( [ & 1 ] ) , Some ( [ & mut 10 ] ) ) ;
859
+ assert_eq ! ( map. get_disjoint_mut( [ & 1 ] ) , [ Some ( & mut 10 ) ] ) ;
857
860
}
858
861
859
862
#[ test]
@@ -863,11 +866,22 @@ fn disjoint_mut_multi_success() {
863
866
map. insert ( 2 , 200 ) ;
864
867
map. insert ( 3 , 300 ) ;
865
868
map. insert ( 4 , 400 ) ;
866
- assert_eq ! ( map. get_disjoint_mut( [ & 1 , & 2 ] ) , Some ( [ & mut 100 , & mut 200 ] ) ) ;
867
- assert_eq ! ( map. get_disjoint_mut( [ & 1 , & 3 ] ) , Some ( [ & mut 100 , & mut 300 ] ) ) ;
869
+ assert_eq ! (
870
+ map. get_disjoint_mut( [ & 1 , & 2 ] ) ,
871
+ [ Some ( & mut 100 ) , Some ( & mut 200 ) ]
872
+ ) ;
873
+ assert_eq ! (
874
+ map. get_disjoint_mut( [ & 1 , & 3 ] ) ,
875
+ [ Some ( & mut 100 ) , Some ( & mut 300 ) ]
876
+ ) ;
868
877
assert_eq ! (
869
878
map. get_disjoint_mut( [ & 3 , & 1 , & 4 , & 2 ] ) ,
870
- Some ( [ & mut 300 , & mut 100 , & mut 400 , & mut 200 ] )
879
+ [
880
+ Some ( & mut 300 ) ,
881
+ Some ( & mut 100 ) ,
882
+ Some ( & mut 400 ) ,
883
+ Some ( & mut 200 )
884
+ ]
871
885
) ;
872
886
}
873
887
@@ -878,44 +892,117 @@ fn disjoint_mut_multi_success_unsized_key() {
878
892
map. insert ( "2" , 200 ) ;
879
893
map. insert ( "3" , 300 ) ;
880
894
map. insert ( "4" , 400 ) ;
881
- assert_eq ! ( map. get_disjoint_mut( [ "1" , "2" ] ) , Some ( [ & mut 100 , & mut 200 ] ) ) ;
882
- assert_eq ! ( map. get_disjoint_mut( [ "1" , "3" ] ) , Some ( [ & mut 100 , & mut 300 ] ) ) ;
895
+
896
+ assert_eq ! (
897
+ map. get_disjoint_mut( [ "1" , "2" ] ) ,
898
+ [ Some ( & mut 100 ) , Some ( & mut 200 ) ]
899
+ ) ;
900
+ assert_eq ! (
901
+ map. get_disjoint_mut( [ "1" , "3" ] ) ,
902
+ [ Some ( & mut 100 ) , Some ( & mut 300 ) ]
903
+ ) ;
883
904
assert_eq ! (
884
905
map. get_disjoint_mut( [ "3" , "1" , "4" , "2" ] ) ,
885
- Some ( [ & mut 300 , & mut 100 , & mut 400 , & mut 200 ] )
906
+ [
907
+ Some ( & mut 300 ) ,
908
+ Some ( & mut 100 ) ,
909
+ Some ( & mut 400 ) ,
910
+ Some ( & mut 200 )
911
+ ]
912
+ ) ;
913
+ }
914
+
915
+ #[ test]
916
+ fn disjoint_mut_multi_success_borrow_key ( ) {
917
+ let mut map: IndexMap < String , u32 > = IndexMap :: default ( ) ;
918
+ map. insert ( "1" . into ( ) , 100 ) ;
919
+ map. insert ( "2" . into ( ) , 200 ) ;
920
+ map. insert ( "3" . into ( ) , 300 ) ;
921
+ map. insert ( "4" . into ( ) , 400 ) ;
922
+
923
+ assert_eq ! (
924
+ map. get_disjoint_mut( [ "1" , "2" ] ) ,
925
+ [ Some ( & mut 100 ) , Some ( & mut 200 ) ]
926
+ ) ;
927
+ assert_eq ! (
928
+ map. get_disjoint_mut( [ "1" , "3" ] ) ,
929
+ [ Some ( & mut 100 ) , Some ( & mut 300 ) ]
930
+ ) ;
931
+ assert_eq ! (
932
+ map. get_disjoint_mut( [ "3" , "1" , "4" , "2" ] ) ,
933
+ [
934
+ Some ( & mut 300 ) ,
935
+ Some ( & mut 100 ) ,
936
+ Some ( & mut 400 ) ,
937
+ Some ( & mut 200 )
938
+ ]
886
939
) ;
887
940
}
888
941
889
942
#[ test]
890
943
fn disjoint_mut_multi_fail_missing ( ) {
944
+ let mut map: IndexMap < u32 , u32 > = IndexMap :: default ( ) ;
945
+ map. insert ( 1 , 100 ) ;
946
+ map. insert ( 2 , 200 ) ;
947
+ map. insert ( 3 , 300 ) ;
948
+ map. insert ( 4 , 400 ) ;
949
+
950
+ assert_eq ! ( map. get_disjoint_mut( [ & 1 , & 5 ] ) , [ Some ( & mut 100 ) , None ] ) ;
951
+ assert_eq ! ( map. get_disjoint_mut( [ & 5 , & 6 ] ) , [ None , None ] ) ;
952
+ assert_eq ! (
953
+ map. get_disjoint_mut( [ & 1 , & 5 , & 4 ] ) ,
954
+ [ Some ( & mut 100 ) , None , Some ( & mut 400 ) ]
955
+ ) ;
956
+ }
957
+
958
+ #[ test]
959
+ #[ should_panic]
960
+ fn disjoint_mut_multi_fail_duplicate_panic ( ) {
961
+ let mut map: IndexMap < u32 , u32 > = IndexMap :: default ( ) ;
962
+ map. insert ( 1 , 100 ) ;
963
+ map. get_disjoint_mut ( [ & 1 , & 2 , & 1 ] ) ;
964
+ }
965
+
966
+ #[ test]
967
+ fn disjoint_indices_mut_fail_oob ( ) {
968
+ let mut map: IndexMap < u32 , u32 > = IndexMap :: default ( ) ;
969
+ map. insert ( 1 , 10 ) ;
970
+ map. insert ( 321 , 20 ) ;
971
+ assert_eq ! (
972
+ map. get_disjoint_indices_mut( [ 1 , 3 ] ) ,
973
+ Err ( crate :: GetDisjointMutError :: IndexOutOfBounds )
974
+ ) ;
975
+ }
976
+
977
+ #[ test]
978
+ fn disjoint_indices_mut_empty ( ) {
891
979
let mut map: IndexMap < u32 , u32 > = IndexMap :: default ( ) ;
892
980
map. insert ( 1 , 10 ) ;
893
- map. insert ( 1123 , 100 ) ;
894
981
map. insert ( 321 , 20 ) ;
895
- map. insert ( 1337 , 30 ) ;
896
- assert_eq ! ( map. get_disjoint_mut( [ & 121 , & 1123 ] ) , None ) ;
897
- assert_eq ! ( map. get_disjoint_mut( [ & 1 , & 1337 , & 56 ] ) , None ) ;
898
- assert_eq ! ( map. get_disjoint_mut( [ & 1337 , & 123 , & 321 , & 1 , & 1123 ] ) , None ) ;
982
+ assert_eq ! ( map. get_disjoint_indices_mut( [ ] ) , Ok ( [ ] ) ) ;
899
983
}
900
984
901
985
#[ test]
902
- fn disjoint_mut_multi_fail_duplicate ( ) {
986
+ fn disjoint_indices_mut_success ( ) {
903
987
let mut map: IndexMap < u32 , u32 > = IndexMap :: default ( ) ;
904
988
map. insert ( 1 , 10 ) ;
905
- map. insert ( 1123 , 100 ) ;
906
989
map. insert ( 321 , 20 ) ;
907
- map. insert ( 1337 , 30 ) ;
908
- assert_eq ! ( map. get_disjoint_mut( [ & 1 , & 1 ] ) , None ) ;
990
+ assert_eq ! ( map. get_disjoint_indices_mut( [ 0 ] ) , Ok ( [ ( & 1 , & mut 10 ) ] ) ) ;
991
+
992
+ assert_eq ! ( map. get_disjoint_indices_mut( [ 1 ] ) , Ok ( [ ( & 321 , & mut 20 ) ] ) ) ;
909
993
assert_eq ! (
910
- map. get_disjoint_mut ( [ & 1337 , & 123 , & 321 , & 1337 , & 1 , & 1123 ] ) ,
911
- None
994
+ map. get_disjoint_indices_mut ( [ 0 , 1 ] ) ,
995
+ Ok ( [ ( & 1 , & mut 10 ) , ( & 321 , & mut 20 ) ] )
912
996
) ;
913
997
}
914
998
915
999
#[ test]
916
- fn many_index_mut_fail_oob ( ) {
1000
+ fn disjoint_indices_mut_fail_duplicate ( ) {
917
1001
let mut map: IndexMap < u32 , u32 > = IndexMap :: default ( ) ;
918
1002
map. insert ( 1 , 10 ) ;
919
1003
map. insert ( 321 , 20 ) ;
920
- assert_eq ! ( map. get_disjoint_indices_mut( [ 1 , 3 ] ) , None ) ;
1004
+ assert_eq ! (
1005
+ map. get_disjoint_indices_mut( [ 1 , 2 , 1 ] ) ,
1006
+ Err ( crate :: GetDisjointMutError :: OverlappingIndices )
1007
+ ) ;
921
1008
}
0 commit comments