@@ -23,18 +23,30 @@ use std::fmt::{self, Debug, Formatter};
2323use std:: sync:: Arc ;
2424#[ cfg( feature = "surf" ) ]
2525use surf:: { Client as HttpClient , RequestBuilder , Response as HttpResponse } ;
26+ use std:: marker:: PhantomData ;
2627
2728use crate :: query:: QueryType ;
2829use crate :: Error ;
2930use crate :: Query ;
3031
32+ /// Marker type for InfluxDB Version 1
33+ #[ derive( Clone ) ]
34+ pub struct InfluxVersion1 ;
35+ /// Marker type for InfluxDB Version 2
36+ #[ derive( Clone ) ]
37+ pub struct InfluxVersion2 ;
38+ /// Marker type for InfluxDB Version 3
39+ #[ derive( Clone ) ]
40+ pub struct InfluxVersion3 ;
41+
3142#[ derive( Clone ) ]
3243/// Internal Representation of a Client
33- pub struct Client {
44+ pub struct Client < V , H = reqwest :: Client > {
3445 pub ( crate ) url : Arc < String > ,
3546 pub ( crate ) parameters : Arc < HashMap < & ' static str , String > > ,
3647 pub ( crate ) token : Option < String > ,
37- pub ( crate ) client : HttpClient ,
48+ pub ( crate ) client : H ,
49+ _version : PhantomData < V > ,
3850}
3951
4052struct RedactPassword < ' a > ( & ' a HashMap < & ' static str , String > ) ;
@@ -53,7 +65,7 @@ impl<'a> Debug for RedactPassword<'a> {
5365 }
5466}
5567
56- impl Debug for Client {
68+ impl < V , H > Debug for Client < V , H > {
5769 fn fmt ( & self , f : & mut Formatter < ' _ > ) -> fmt:: Result {
5870 f. debug_struct ( "Client" )
5971 . field ( "url" , & self . url )
@@ -62,7 +74,7 @@ impl Debug for Client {
6274 }
6375}
6476
65- impl Client {
77+ impl < V > Client < V , reqwest :: Client > {
6678 /// Instantiates a new [`Client`](crate::Client)
6779 ///
6880 /// # Arguments
@@ -90,6 +102,7 @@ impl Client {
90102 parameters : Arc :: new ( parameters) ,
91103 client : HttpClient :: new ( ) ,
92104 token : None ,
105+ _version : PhantomData ,
93106 }
94107 }
95108
@@ -308,12 +321,15 @@ pub(crate) fn check_status(res: &HttpResponse) -> Result<(), Error> {
308321
309322#[ cfg( test) ]
310323mod tests {
324+
325+ use crate :: client:: InfluxVersion1 ;
326+
311327 use super :: Client ;
312328 use indoc:: indoc;
313329
314330 #[ test]
315331 fn test_client_debug_redacted_password ( ) {
316- let client = Client :: new ( "https://localhost:8086" , "db" ) . with_auth ( "user" , "pass" ) ;
332+ let client: Client < InfluxVersion1 > = Client :: new ( "https://localhost:8086" , "db" ) . with_auth ( "user" , "pass" ) ;
317333 let actual = format ! ( "{client:#?}" ) ;
318334 let expected = indoc ! { r#"
319335 Client {
@@ -331,14 +347,14 @@ mod tests {
331347
332348 #[ test]
333349 fn test_fn_database ( ) {
334- let client = Client :: new ( "http://localhost:8068" , "database" ) ;
350+ let client: Client < InfluxVersion1 > = Client :: new ( "http://localhost:8068" , "database" ) ;
335351 assert_eq ! ( client. database_name( ) , "database" ) ;
336352 assert_eq ! ( client. database_url( ) , "http://localhost:8068" ) ;
337353 }
338354
339355 #[ test]
340356 fn test_with_auth ( ) {
341- let client = Client :: new ( "http://localhost:8068" , "database" ) ;
357+ let client: Client < InfluxVersion1 > = Client :: new ( "http://localhost:8068" , "database" ) ;
342358 assert_eq ! ( client. parameters. len( ) , 1 ) ;
343359 assert_eq ! ( client. parameters. get( "db" ) . unwrap( ) , "database" ) ;
344360
@@ -348,7 +364,7 @@ mod tests {
348364 assert_eq ! ( with_auth. parameters. get( "u" ) . unwrap( ) , "username" ) ;
349365 assert_eq ! ( with_auth. parameters. get( "p" ) . unwrap( ) , "password" ) ;
350366
351- let client = Client :: new ( "http://localhost:8068" , "database" ) ;
367+ let client: Client < InfluxVersion1 > = Client :: new ( "http://localhost:8068" , "database" ) ;
352368 let with_auth = client. with_token ( "token" ) ;
353369 assert_eq ! ( with_auth. parameters. len( ) , 1 ) ;
354370 assert_eq ! ( with_auth. parameters. get( "db" ) . unwrap( ) , "database" ) ;
0 commit comments