1
1
//! Provides types for dealing with CQL value deserialization.
2
2
3
+ use bytes:: Bytes ;
3
4
use std:: {
4
5
collections:: { BTreeMap , BTreeSet , HashMap , HashSet } ,
5
6
hash:: { BuildHasher , Hash } ,
6
7
net:: IpAddr ,
7
8
} ;
8
-
9
- use bytes:: Bytes ;
10
9
use uuid:: Uuid ;
11
10
12
11
use std:: fmt:: { Display , Pointer } ;
@@ -759,7 +758,7 @@ pub struct VectorIterator<'frame, T> {
759
758
}
760
759
761
760
impl < ' frame , T > VectorIterator < ' frame , T > {
762
- fn new (
761
+ pub fn new (
763
762
coll_typ : & ' frame ColumnType ,
764
763
elem_typ : & ' frame ColumnType ,
765
764
count : usize ,
@@ -774,6 +773,25 @@ impl<'frame, T> VectorIterator<'frame, T> {
774
773
phantom_data : std:: marker:: PhantomData ,
775
774
}
776
775
}
776
+
777
+ /// Faster specialization for deserializing a `vector<float>` into `Vec<CqlValue>`.
778
+ /// The generic code `Vec<CqlValue>::deserialize(...)` is much slower because it has to
779
+ /// match on the element type for every item in the vector.
780
+ /// Here we just hardcode `f32` and we can shortcut a lot of code.
781
+ ///
782
+ /// This could be nicer if Rust had generic type specialization in stable,
783
+ /// but for now we need a separate method.
784
+ pub fn deserialize_vector_of_float_to_vec_of_cql_value (
785
+ typ : & ' frame ColumnType ,
786
+ v : Option < FrameSlice < ' frame > > ,
787
+ ) -> Result < Vec < CqlValue > , DeserializationError > {
788
+ VectorIterator :: < ' frame , f32 > :: deserialize ( typ, v)
789
+ . and_then ( |it| {
790
+ it. map ( |e| e. map ( CqlValue :: Float ) )
791
+ . collect :: < Result < Vec < CqlValue > , DeserializationError > > ( )
792
+ } )
793
+ . map_err ( deser_error_replace_rust_name :: < Self > )
794
+ }
777
795
}
778
796
779
797
impl < ' frame , T > DeserializeValue < ' frame > for VectorIterator < ' frame , T >
@@ -883,6 +901,7 @@ where
883
901
. and_then ( |it| it. collect :: < Result < _ , DeserializationError > > ( ) )
884
902
. map_err ( deser_error_replace_rust_name :: < Self > )
885
903
}
904
+
886
905
ColumnType :: Vector ( _, _) => VectorIterator :: < ' frame , T > :: deserialize ( typ, v)
887
906
. and_then ( |it| it. collect :: < Result < _ , DeserializationError > > ( ) )
888
907
. map_err ( deser_error_replace_rust_name :: < Self > ) ,
0 commit comments