@@ -832,28 +832,31 @@ move_index_oob!(test_move_index_out_of_bounds_max_0, usize::MAX, 0);
832832#[ test]
833833fn disjoint_mut_empty_map ( ) {
834834 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+ ) ;
836839}
837840
838841#[ test]
839842fn disjoint_mut_empty_param ( ) {
840843 let mut map: IndexMap < u32 , u32 > = IndexMap :: default ( ) ;
841844 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 ] ) , [ ] ) ;
843846}
844847
845848#[ test]
846849fn disjoint_mut_single_fail ( ) {
847850 let mut map: IndexMap < u32 , u32 > = IndexMap :: default ( ) ;
848851 map. insert ( 1 , 10 ) ;
849- assert ! ( map. get_disjoint_mut( [ & 0 ] ) . is_none ( ) ) ;
852+ assert_eq ! ( map. get_disjoint_mut( [ & 0 ] ) , [ None ] ) ;
850853}
851854
852855#[ test]
853856fn disjoint_mut_single_success ( ) {
854857 let mut map: IndexMap < u32 , u32 > = IndexMap :: default ( ) ;
855858 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 ) ] ) ;
857860}
858861
859862#[ test]
@@ -863,11 +866,22 @@ fn disjoint_mut_multi_success() {
863866 map. insert ( 2 , 200 ) ;
864867 map. insert ( 3 , 300 ) ;
865868 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+ ) ;
868877 assert_eq ! (
869878 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+ ]
871885 ) ;
872886}
873887
@@ -878,44 +892,117 @@ fn disjoint_mut_multi_success_unsized_key() {
878892 map. insert ( "2" , 200 ) ;
879893 map. insert ( "3" , 300 ) ;
880894 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+ ) ;
883904 assert_eq ! (
884905 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+ ]
886939 ) ;
887940}
888941
889942#[ test]
890943fn 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 ( ) {
891979 let mut map: IndexMap < u32 , u32 > = IndexMap :: default ( ) ;
892980 map. insert ( 1 , 10 ) ;
893- map. insert ( 1123 , 100 ) ;
894981 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 ( [ ] ) ) ;
899983}
900984
901985#[ test]
902- fn disjoint_mut_multi_fail_duplicate ( ) {
986+ fn disjoint_indices_mut_success ( ) {
903987 let mut map: IndexMap < u32 , u32 > = IndexMap :: default ( ) ;
904988 map. insert ( 1 , 10 ) ;
905- map. insert ( 1123 , 100 ) ;
906989 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 ) ] ) ) ;
909993 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 ) ] )
912996 ) ;
913997}
914998
915999#[ test]
916- fn many_index_mut_fail_oob ( ) {
1000+ fn disjoint_indices_mut_fail_duplicate ( ) {
9171001 let mut map: IndexMap < u32 , u32 > = IndexMap :: default ( ) ;
9181002 map. insert ( 1 , 10 ) ;
9191003 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+ ) ;
9211008}
0 commit comments