4
4
5
5
use crate :: query:: { QueryType , ValidQuery } ;
6
6
use crate :: { Error , Query , Timestamp } ;
7
+ use std:: fmt:: { Display , Formatter } ;
7
8
8
9
// todo: batch write queries
9
10
@@ -19,12 +20,12 @@ impl WriteQuery {
19
20
/// Creates a new [`WriteQuery`](crate::query::write_query::WriteQuery)
20
21
pub fn new < S > ( timestamp : Timestamp , measurement : S ) -> Self
21
22
where
22
- S : ToString ,
23
+ S : Into < String > ,
23
24
{
24
25
WriteQuery {
25
26
fields : vec ! [ ] ,
26
27
tags : vec ! [ ] ,
27
- measurement : measurement. to_string ( ) ,
28
+ measurement : measurement. into ( ) ,
28
29
timestamp,
29
30
}
30
31
}
@@ -40,11 +41,11 @@ impl WriteQuery {
40
41
/// ```
41
42
pub fn add_field < S , I > ( mut self , tag : S , value : I ) -> Self
42
43
where
43
- S : ToString ,
44
+ S : Into < String > ,
44
45
I : Into < Type > ,
45
46
{
46
47
let val: Type = value. into ( ) ;
47
- self . fields . push ( ( tag. to_string ( ) , val. to_string ( ) ) ) ;
48
+ self . fields . push ( ( tag. into ( ) , val. to_string ( ) ) ) ;
48
49
self
49
50
}
50
51
@@ -63,11 +64,11 @@ impl WriteQuery {
63
64
/// ```
64
65
pub fn add_tag < S , I > ( mut self , tag : S , value : I ) -> Self
65
66
where
66
- S : ToString ,
67
+ S : Into < String > ,
67
68
I : Into < Type > ,
68
69
{
69
70
let val: Type = value. into ( ) ;
70
- self . tags . push ( ( tag. to_string ( ) , val. to_string ( ) ) ) ;
71
+ self . tags . push ( ( tag. into ( ) , val. to_string ( ) ) ) ;
71
72
self
72
73
}
73
74
@@ -93,16 +94,16 @@ pub enum Type {
93
94
Text ( String ) ,
94
95
}
95
96
96
- impl ToString for Type {
97
- fn to_string ( & self ) -> String {
97
+ impl Display for Type {
98
+ fn fmt ( & self , f : & mut Formatter ) -> std :: fmt :: Result {
98
99
use Type :: * ;
99
100
100
101
match self {
101
- Boolean ( x) => x . to_string ( ) ,
102
- Float ( x) => x . to_string ( ) ,
103
- SignedInteger ( x) => x . to_string ( ) ,
104
- UnsignedInteger ( x) => x . to_string ( ) ,
105
- Text ( text) => format ! ( "\" {text}\" " , text = text) ,
102
+ Boolean ( x) => write ! ( f , "{}" , x ) ,
103
+ Float ( x) => write ! ( f , "{}" , x ) ,
104
+ SignedInteger ( x) => write ! ( f , "{}" , x ) ,
105
+ UnsignedInteger ( x) => write ! ( f , "{}" , x ) ,
106
+ Text ( text) => write ! ( f , "\" {text}\" " , text = text) ,
106
107
}
107
108
}
108
109
}
0 commit comments