@@ -780,58 +780,73 @@ fn deser_table_spec_for_col_spec<'frame>(
780780 Ok ( table_spec)
781781}
782782
783- macro_rules! generate_deser_col_specs {
784- ( $deser_col_specs: ident, $l: lifetime, $deser_type: ident, $make_col_spec: expr $( , ) ?) => {
785- /// Deserializes col specs (part of ResultMetadata or PreparedMetadata)
786- /// in the form mentioned by its name.
787- ///
788- /// Checks for equality of table specs across columns, because the protocol
789- /// does not guarantee that and we want to be sure that the assumption
790- /// of them being all the same is correct.
791- ///
792- /// To avoid needless allocations, it is advised to pass `global_table_spec`
793- /// in the borrowed form, so that cloning it is cheap.
794- fn $deser_col_specs<' frame>(
795- buf: & mut & ' frame [ u8 ] ,
796- global_table_spec: Option <TableSpec <' frame>>,
797- col_count: usize ,
798- ) -> StdResult <Vec <ColumnSpec <$l>>, ColumnSpecParseError > {
799- let global_table_spec_provided = global_table_spec. is_some( ) ;
800- let mut known_table_spec = global_table_spec;
801-
802- let mut col_specs = Vec :: with_capacity( col_count) ;
803- for col_idx in 0 ..col_count {
804- let table_spec = deser_table_spec_for_col_spec(
805- buf,
806- global_table_spec_provided,
807- & mut known_table_spec,
808- col_idx,
809- ) ?;
810-
811- let name =
812- types:: read_string( buf) . map_err( |err| mk_col_spec_parse_error( col_idx, err) ) ?;
813- let typ = $deser_type( buf) . map_err( |err| mk_col_spec_parse_error( col_idx, err) ) ?;
814- let col_spec = $make_col_spec( name, typ, table_spec) ;
815- col_specs. push( col_spec) ;
816- }
817- Ok ( col_specs)
818- }
819- } ;
783+ /// Deserializes col specs (part of ResultMetadata or PreparedMetadata)
784+ /// in the form mentioned by its name.
785+ ///
786+ /// Checks for equality of table specs across columns, because the protocol
787+ /// does not guarantee that and we want to be sure that the assumption
788+ /// of them being all the same is correct.
789+ ///
790+ /// To avoid needless allocations, it is advised to pass `global_table_spec`
791+ /// in the borrowed form, so that cloning it is cheap.
792+ fn deser_col_specs_generic < ' frame , ' result > (
793+ buf : & mut & ' frame [ u8 ] ,
794+ global_table_spec : Option < TableSpec < ' frame > > ,
795+ col_count : usize ,
796+ make_col_spec : fn ( & ' frame str , ColumnType < ' result > , TableSpec < ' frame > ) -> ColumnSpec < ' result > ,
797+ deser_type : fn ( & mut & ' frame [ u8 ] ) -> StdResult < ColumnType < ' result > , CqlTypeParseError > ,
798+ ) -> StdResult < Vec < ColumnSpec < ' result > > , ColumnSpecParseError > {
799+ let global_table_spec_provided = global_table_spec. is_some ( ) ;
800+ let mut known_table_spec = global_table_spec;
801+
802+ let mut col_specs = Vec :: with_capacity ( col_count) ;
803+ for col_idx in 0 ..col_count {
804+ let table_spec = deser_table_spec_for_col_spec (
805+ buf,
806+ global_table_spec_provided,
807+ & mut known_table_spec,
808+ col_idx,
809+ ) ?;
810+
811+ let name = types:: read_string ( buf) . map_err ( |err| mk_col_spec_parse_error ( col_idx, err) ) ?;
812+ let typ = deser_type ( buf) . map_err ( |err| mk_col_spec_parse_error ( col_idx, err) ) ?;
813+ let col_spec = make_col_spec ( name, typ, table_spec) ;
814+ col_specs. push ( col_spec) ;
815+ }
816+ Ok ( col_specs)
817+ }
818+
819+ fn _deser_col_specs_borrowed < ' frame > (
820+ buf : & mut & ' frame [ u8 ] ,
821+ global_table_spec : Option < TableSpec < ' frame > > ,
822+ col_count : usize ,
823+ ) -> StdResult < Vec < ColumnSpec < ' frame > > , ColumnSpecParseError > {
824+ deser_col_specs_generic (
825+ buf,
826+ global_table_spec,
827+ col_count,
828+ ColumnSpec :: borrowed,
829+ _deser_type_borrowed,
830+ )
820831}
821832
822- generate_deser_col_specs ! (
823- _deser_col_specs_borrowed,
824- ' frame,
825- _deser_type_borrowed,
826- ColumnSpec :: borrowed,
827- ) ;
828-
829- generate_deser_col_specs ! (
830- deser_col_specs_owned,
831- ' static ,
832- deser_type_owned,
833- |name: & str , typ, table_spec: TableSpec | ColumnSpec :: owned( name. to_owned( ) , typ, table_spec. into_owned( ) ) ,
834- ) ;
833+ fn deser_col_specs_owned < ' frame > (
834+ buf : & mut & ' frame [ u8 ] ,
835+ global_table_spec : Option < TableSpec < ' frame > > ,
836+ col_count : usize ,
837+ ) -> StdResult < Vec < ColumnSpec < ' static > > , ColumnSpecParseError > {
838+ let result: StdResult < Vec < ColumnSpec < ' static > > , ColumnSpecParseError > = deser_col_specs_generic (
839+ buf,
840+ global_table_spec,
841+ col_count,
842+ |name : & str , typ, table_spec : TableSpec | {
843+ ColumnSpec :: owned ( name. to_owned ( ) , typ, table_spec. into_owned ( ) )
844+ } ,
845+ deser_type_owned,
846+ ) ;
847+
848+ result
849+ }
835850
836851fn deser_result_metadata (
837852 buf : & mut & [ u8 ] ,
0 commit comments