1- use serde_json;
2- use serde_json:: de:: IoRead as SerdeIoRead ;
31use hyper:: client:: Client as hyper_client;
2+ use hyper:: client:: RequestBuilder ;
43use hyper:: client:: Response ;
54use hyper:: net:: HttpsConnector ;
6- use hyper:: client :: RequestBuilder ;
5+ use hyper:: Url ;
76use hyper_native_tls:: native_tls:: TlsConnector ;
87use hyper_native_tls:: NativeTlsClient ;
9- use hyper:: Url ;
8+ use serde_json;
9+ use serde_json:: de:: IoRead as SerdeIoRead ;
1010use std:: io:: Read ;
11- use std:: time:: Duration ;
12- use std:: net:: UdpSocket ;
1311use std:: iter:: FromIterator ;
12+ use std:: net:: UdpSocket ;
1413use std:: net:: { SocketAddr , ToSocketAddrs } ;
15- use { error, serialization, Node , Point , Points , Precision , Query , ChunkedQuery } ;
14+ use std:: time:: Duration ;
15+ use { error, serialization, ChunkedQuery , Node , Point , Points , Precision , Query } ;
1616
1717/// The client to influxdb
1818#[ derive( Debug ) ]
@@ -137,10 +137,9 @@ impl Client {
137137 None => param. push ( ( "precision" , "s" ) ) ,
138138 } ;
139139
140- match rp {
141- Some ( t) => param. push ( ( "rp" , t) ) ,
142- None => ( ) ,
143- } ;
140+ if let Some ( t) = rp {
141+ param. push ( ( "rp" , t) )
142+ }
144143
145144 let url = self . build_url ( "write" , Some ( param) ) ;
146145
@@ -150,12 +149,12 @@ impl Client {
150149
151150 match res. status_raw ( ) . 0 {
152151 204 => Ok ( ( ) ) ,
153- 400 => Err ( error:: Error :: SyntaxError ( serialization:: conversion ( err) ) ) ,
152+ 400 => Err ( error:: Error :: SyntaxError ( serialization:: conversion ( & err) ) ) ,
154153 401 | 403 => Err ( error:: Error :: InvalidCredentials (
155154 "Invalid authentication credentials." . to_string ( ) ,
156155 ) ) ,
157156 404 => Err ( error:: Error :: DataBaseDoesNotExist (
158- serialization:: conversion ( err) ,
157+ serialization:: conversion ( & err) ,
159158 ) ) ,
160159 500 => Err ( error:: Error :: RetentionPolicyDoesNotExist ( err) ) ,
161160 _ => Err ( error:: Error :: Unknow ( "There is something wrong" . to_string ( ) ) ) ,
@@ -180,7 +179,7 @@ impl Client {
180179 q : & str ,
181180 epoch : Option < Precision > ,
182181 ) -> Result < ChunkedQuery < SerdeIoRead < Response > > , error:: Error > {
183- return self . query_raw_chunked ( q, epoch) ;
182+ self . query_raw_chunked ( q, epoch)
184183 }
185184
186185 /// Drop measurement
@@ -405,12 +404,16 @@ impl Client {
405404 }
406405 }
407406
408- fn send_request ( & self , q : & str , epoch : Option < Precision > , chunked : bool ) -> Result < Response , error:: Error > {
407+ fn send_request (
408+ & self ,
409+ q : & str ,
410+ epoch : Option < Precision > ,
411+ chunked : bool ,
412+ ) -> Result < Response , error:: Error > {
409413 let mut param = vec ! [ ( "db" , self . db. as_str( ) ) , ( "q" , q) ] ;
410414
411- match epoch {
412- Some ( ref t) => param. push ( ( "epoch" , t. to_str ( ) ) ) ,
413- None => ( ) ,
415+ if let Some ( ref t) = epoch {
416+ param. push ( ( "epoch" , t. to_str ( ) ) )
414417 }
415418
416419 if chunked {
@@ -423,9 +426,9 @@ impl Client {
423426 let mut res = {
424427 if q_lower. starts_with ( "select" ) && !q_lower. contains ( "into" )
425428 || q_lower. starts_with ( "show" )
426- {
427- self . client . get ( url) . send ( ) ?
428- } else {
429+ {
430+ self . client . get ( url) . send ( ) ?
431+ } else {
429432 self . client . post ( url) . send ( ) ?
430433 }
431434 } ;
@@ -438,9 +441,9 @@ impl Client {
438441 let json_data: Query = serde_json:: from_str ( & context) . unwrap ( ) ;
439442
440443 Err ( error:: Error :: SyntaxError ( serialization:: conversion (
441- json_data. error . unwrap ( ) ,
444+ & json_data. error . unwrap ( ) ,
442445 ) ) )
443- } ,
446+ }
444447 401 | 403 => Err ( error:: Error :: InvalidCredentials (
445448 "Invalid authentication credentials." . to_string ( ) ,
446449 ) ) ,
@@ -456,14 +459,18 @@ impl Client {
456459 let _ = response. read_to_string ( & mut context) ;
457460
458461 let json_data: Query = serde_json:: from_str ( & context) . unwrap ( ) ;
459- return Ok ( json_data) ;
462+ Ok ( json_data)
460463 }
461464
462465 /// Query and return to the native json structure
463- fn query_raw_chunked ( & self , q : & str , epoch : Option < Precision > ) -> Result < ChunkedQuery < SerdeIoRead < Response > > , error:: Error > {
466+ fn query_raw_chunked (
467+ & self ,
468+ q : & str ,
469+ epoch : Option < Precision > ,
470+ ) -> Result < ChunkedQuery < SerdeIoRead < Response > > , error:: Error > {
464471 let response = self . send_request ( q, epoch, true ) ?;
465472 let stream = serde_json:: Deserializer :: from_reader ( response) . into_iter :: < Query > ( ) ;
466- return Ok ( stream) ;
473+ Ok ( stream)
467474 }
468475
469476 /// Constructs the full URL for an API call.
@@ -472,12 +479,9 @@ impl Client {
472479
473480 let mut authentication = Vec :: new ( ) ;
474481
475- match self . authentication {
476- Some ( ref t) => {
477- authentication. push ( ( "u" , & t. 0 ) ) ;
478- authentication. push ( ( "p" , & t. 1 ) ) ;
479- }
480- None => { }
482+ if let Some ( ref t) = self . authentication {
483+ authentication. push ( ( "u" , & t. 0 ) ) ;
484+ authentication. push ( ( "p" , & t. 1 ) ) ;
481485 }
482486
483487 let url = Url :: parse_with_params ( url. as_str ( ) , authentication) . unwrap ( ) ;
0 commit comments