@@ -38,7 +38,7 @@ pub struct InfluxDbSeries<T> {
38
38
}
39
39
40
40
impl 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 > >
42
42
where
43
43
Q : InfluxDbQuery ,
44
44
T : DeserializeOwned ,
@@ -56,7 +56,7 @@ impl InfluxDbClient {
56
56
let error = InfluxDbError :: UnspecifiedError {
57
57
error : format ! ( "{}" , err) ,
58
58
} ;
59
- return Box :: new ( future:: err :: < Option < Vec < T > > , InfluxDbError > ( error) ) ;
59
+ return Box :: new ( future:: err :: < Option < Vec < InfluxDbSeries < T > > > , InfluxDbError > ( error) ) ;
60
60
}
61
61
Ok ( query) => query,
62
62
} ;
@@ -102,13 +102,13 @@ impl InfluxDbClient {
102
102
error : format ! ( "{}" , err)
103
103
} )
104
104
. and_then ( |body| {
105
- println ! ( "{:?}" , & body) ;
106
105
// Try parsing InfluxDBs { "error": "error message here" }
107
106
if let Ok ( error) = serde_json:: from_slice :: < _DatabaseError > ( & body) {
108
107
return futures:: future:: err ( InfluxDbError :: DatabaseError {
109
108
error : error. error . to_string ( )
110
109
} )
111
110
} else {
111
+ // Json has another structure, let's try actually parsing it to the type we're deserializing
112
112
let from_slice = serde_json:: from_slice :: < DatabaseQueryResult < T > > ( & body) ;
113
113
114
114
let mut deserialized = match from_slice {
@@ -118,12 +118,7 @@ impl InfluxDbClient {
118
118
} )
119
119
} ;
120
120
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 ) ) ;
127
122
}
128
123
} )
129
124
)
0 commit comments