@@ -835,35 +835,39 @@ fn _pythondto_array_to_serde(
835
835
dimension_index : usize ,
836
836
mut lower_bound : usize ,
837
837
) -> RustPSQLDriverPyResult < Value > {
838
- let current_dimension = dimensions. get ( dimension_index) . unwrap ( ) ;
839
-
840
- let possible_next_dimension = dimensions. get ( dimension_index + 1 ) ;
841
- match possible_next_dimension {
842
- Some ( next_dimension) => {
843
- let mut final_list: Value = Value :: Array ( vec ! [ ] ) ;
844
-
845
- for _ in 0 ..current_dimension. len as usize {
846
- if dimensions. get ( dimension_index + 1 ) . is_some ( ) {
847
- let inner_pylist = _pythondto_array_to_serde (
848
- dimensions,
849
- & data[ lower_bound..next_dimension. len as usize + lower_bound] ,
850
- dimension_index + 1 ,
851
- 0 ,
852
- ) ?;
853
- match final_list {
854
- Value :: Array ( ref mut array) => array. push ( inner_pylist) ,
855
- _ => unreachable ! ( ) ,
856
- }
857
- lower_bound += next_dimension. len as usize ;
858
- } ;
859
- }
838
+ let current_dimension = dimensions. get ( dimension_index) ;
839
+
840
+ if let Some ( current_dimension) = current_dimension {
841
+ let possible_next_dimension = dimensions. get ( dimension_index + 1 ) ;
842
+ match possible_next_dimension {
843
+ Some ( next_dimension) => {
844
+ let mut final_list: Value = Value :: Array ( vec ! [ ] ) ;
845
+
846
+ for _ in 0 ..current_dimension. len as usize {
847
+ if dimensions. get ( dimension_index + 1 ) . is_some ( ) {
848
+ let inner_pylist = _pythondto_array_to_serde (
849
+ dimensions,
850
+ & data[ lower_bound..next_dimension. len as usize + lower_bound] ,
851
+ dimension_index + 1 ,
852
+ 0 ,
853
+ ) ?;
854
+ match final_list {
855
+ Value :: Array ( ref mut array) => array. push ( inner_pylist) ,
856
+ _ => unreachable ! ( ) ,
857
+ }
858
+ lower_bound += next_dimension. len as usize ;
859
+ } ;
860
+ }
860
861
861
- Ok ( final_list)
862
- }
863
- None => {
864
- return data. iter ( ) . map ( |x| x. to_serde_value ( ) ) . collect ( ) ;
862
+ return Ok ( final_list) ;
863
+ }
864
+ None => {
865
+ return data. iter ( ) . map ( |x| x. to_serde_value ( ) ) . collect ( ) ;
866
+ }
865
867
}
866
868
}
869
+
870
+ Ok ( Value :: Array ( vec ! [ ] ) )
867
871
}
868
872
869
873
/// Convert rust array to python list.
@@ -899,33 +903,37 @@ fn _postgres_array_to_py<T>(
899
903
where
900
904
T : ToPyObject ,
901
905
{
902
- let current_dimension = dimensions. get ( dimension_index) . unwrap ( ) ;
903
-
904
- let possible_next_dimension = dimensions. get ( dimension_index + 1 ) ;
905
- match possible_next_dimension {
906
- Some ( next_dimension) => {
907
- let final_list = PyList :: empty_bound ( py) ;
908
-
909
- for _ in 0 ..current_dimension. len as usize {
910
- if dimensions. get ( dimension_index + 1 ) . is_some ( ) {
911
- let inner_pylist = _postgres_array_to_py (
912
- py,
913
- dimensions,
914
- & data[ lower_bound..next_dimension. len as usize + lower_bound] ,
915
- dimension_index + 1 ,
916
- 0 ,
917
- ) ;
918
- final_list. append ( inner_pylist) . unwrap ( ) ;
919
- lower_bound += next_dimension. len as usize ;
920
- } ;
921
- }
906
+ let current_dimension = dimensions. get ( dimension_index) ;
907
+
908
+ if let Some ( current_dimension) = current_dimension {
909
+ let possible_next_dimension = dimensions. get ( dimension_index + 1 ) ;
910
+ match possible_next_dimension {
911
+ Some ( next_dimension) => {
912
+ let final_list = PyList :: empty_bound ( py) ;
913
+
914
+ for _ in 0 ..current_dimension. len as usize {
915
+ if dimensions. get ( dimension_index + 1 ) . is_some ( ) {
916
+ let inner_pylist = _postgres_array_to_py (
917
+ py,
918
+ dimensions,
919
+ & data[ lower_bound..next_dimension. len as usize + lower_bound] ,
920
+ dimension_index + 1 ,
921
+ 0 ,
922
+ ) ;
923
+ final_list. append ( inner_pylist) . unwrap ( ) ;
924
+ lower_bound += next_dimension. len as usize ;
925
+ } ;
926
+ }
922
927
923
- final_list. unbind ( )
924
- }
925
- None => {
926
- return PyList :: new_bound ( py, data) . unbind ( ) ;
928
+ return final_list. unbind ( ) ;
929
+ }
930
+ None => {
931
+ return PyList :: new_bound ( py, data) . unbind ( ) ;
932
+ }
927
933
}
928
934
}
935
+
936
+ return PyList :: empty_bound ( py) . unbind ( ) ;
929
937
}
930
938
931
939
#[ allow( clippy:: too_many_lines) ]
0 commit comments