44
55use crate :: query:: { QueryType , ValidQuery } ;
66use crate :: { Error , Query , Timestamp } ;
7+ use std:: fmt:: { Display , Formatter } ;
78
89// todo: batch write queries
910
@@ -19,12 +20,12 @@ impl WriteQuery {
1920 /// Creates a new [`WriteQuery`](crate::query::write_query::WriteQuery)
2021 pub fn new < S > ( timestamp : Timestamp , measurement : S ) -> Self
2122 where
22- S : ToString ,
23+ S : Into < String > ,
2324 {
2425 WriteQuery {
2526 fields : vec ! [ ] ,
2627 tags : vec ! [ ] ,
27- measurement : measurement. to_string ( ) ,
28+ measurement : measurement. into ( ) ,
2829 timestamp,
2930 }
3031 }
@@ -40,11 +41,11 @@ impl WriteQuery {
4041 /// ```
4142 pub fn add_field < S , I > ( mut self , tag : S , value : I ) -> Self
4243 where
43- S : ToString ,
44+ S : Into < String > ,
4445 I : Into < Type > ,
4546 {
4647 let val: Type = value. into ( ) ;
47- self . fields . push ( ( tag. to_string ( ) , val. to_string ( ) ) ) ;
48+ self . fields . push ( ( tag. into ( ) , val. to_string ( ) ) ) ;
4849 self
4950 }
5051
@@ -63,11 +64,11 @@ impl WriteQuery {
6364 /// ```
6465 pub fn add_tag < S , I > ( mut self , tag : S , value : I ) -> Self
6566 where
66- S : ToString ,
67+ S : Into < String > ,
6768 I : Into < Type > ,
6869 {
6970 let val: Type = value. into ( ) ;
70- self . tags . push ( ( tag. to_string ( ) , val. to_string ( ) ) ) ;
71+ self . tags . push ( ( tag. into ( ) , val. to_string ( ) ) ) ;
7172 self
7273 }
7374
@@ -93,16 +94,16 @@ pub enum Type {
9394 Text ( String ) ,
9495}
9596
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 {
9899 use Type :: * ;
99100
100101 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) ,
106107 }
107108 }
108109}
0 commit comments