@@ -38,7 +38,7 @@ pub struct InfluxDbSeries<T> {
3838}
3939
4040impl InfluxDbClient {
41- pub fn json_query < T : ' static , Q > ( self , q : Q ) -> Box < dyn Future < Item = Option < Vec < T > > , Error = InfluxDbError > >
41+ pub fn json_query < T : ' static , Q > ( & self , q : Q ) -> Box < dyn Future < Item = Option < Vec < InfluxDbSeries < T > > > , Error = InfluxDbError > >
4242 where
4343 Q : InfluxDbQuery ,
4444 T : DeserializeOwned ,
@@ -56,7 +56,7 @@ impl InfluxDbClient {
5656 let error = InfluxDbError :: UnspecifiedError {
5757 error : format ! ( "{}" , err) ,
5858 } ;
59- return Box :: new ( future:: err :: < Option < Vec < T > > , InfluxDbError > ( error) ) ;
59+ return Box :: new ( future:: err :: < Option < Vec < InfluxDbSeries < T > > > , InfluxDbError > ( error) ) ;
6060 }
6161 Ok ( query) => query,
6262 } ;
@@ -102,13 +102,13 @@ impl InfluxDbClient {
102102 error : format ! ( "{}" , err)
103103 } )
104104 . and_then ( |body| {
105- println ! ( "{:?}" , & body) ;
106105 // Try parsing InfluxDBs { "error": "error message here" }
107106 if let Ok ( error) = serde_json:: from_slice :: < _DatabaseError > ( & body) {
108107 return futures:: future:: err ( InfluxDbError :: DatabaseError {
109108 error : error. error . to_string ( )
110109 } )
111110 } else {
111+ // Json has another structure, let's try actually parsing it to the type we're deserializing
112112 let from_slice = serde_json:: from_slice :: < DatabaseQueryResult < T > > ( & body) ;
113113
114114 let mut deserialized = match from_slice {
@@ -118,12 +118,7 @@ impl InfluxDbClient {
118118 } )
119119 } ;
120120
121- // Json has another structure, let's try actually parsing it to the type we're deserializing to
122- let t_result = match deserialized. results . remove ( 0 ) . series {
123- Some ( series) => Ok ( Some ( series. into_iter ( ) . flat_map ( |x| { x. values } ) . collect :: < Vec < T > > ( ) ) ) ,
124- None => Ok ( None )
125- } ;
126- return futures:: future:: result ( t_result) ;
121+ return futures:: future:: result ( Ok ( deserialized. results . remove ( 0 ) . series ) ) ;
127122 }
128123 } )
129124 )
0 commit comments