1
1
use serde_json:: Value ;
2
-
3
- #[ derive( Debug , Clone , Serialize ) ]
2
+ use std:: borrow:: Cow ;
3
+
4
+ // this modification was necessary because of this bug:
5
+ // [https://github.com/rust-lang/rust/issues/63033](https://github.com/rust-lang/rust/issues/63033).
6
+ // When the bug is resolved we can revert to the original Query from
7
+ // commit:
8
+ // [https://github.com/MindFlavor/AzureSDKForRust/commit/1b6cb32b3478b0afc50c4460100c21f785720b17](https://github.com/MindFlavor/AzureSDKForRust/commit/1b6cb32b3478b0afc50c4460100c21f785720b17)
9
+ #[ derive( Debug , Serialize ) ]
4
10
pub struct Query < ' a > {
5
11
query : & ' a str ,
6
12
parameters : Vec < Param < ' a > > ,
@@ -9,7 +15,7 @@ pub struct Query<'a> {
9
15
#[ derive( Debug , Serialize , Clone ) ]
10
16
pub struct Param < ' a > {
11
17
name : & ' a str ,
12
- value : & ' a Value ,
18
+ value : Value ,
13
19
}
14
20
15
21
#[ derive( Debug , Serialize , Clone ) ]
@@ -18,16 +24,26 @@ pub struct ParamDef<'a> {
18
24
}
19
25
20
26
impl < ' a > Param < ' a > {
21
- pub fn new ( name : & ' a str , value : & ' a Value ) -> Self {
22
- Self { name, value }
27
+ pub fn new < T : Into < Value > > ( name : & ' a str , value : T ) -> Self {
28
+ Self {
29
+ name,
30
+ value : value. into ( ) ,
31
+ }
23
32
}
24
33
34
+ //pub fn new_ref(name: &'a str, value: &'a Value) -> Self {
35
+ // Self {
36
+ // name,
37
+ // value: Cow::Borrowed(value),
38
+ // }
39
+ //}
40
+
25
41
pub fn name ( & self ) -> & ' a str {
26
42
self . name
27
43
}
28
44
29
45
pub fn value ( & self ) -> & Value {
30
- self . value
46
+ & self . value
31
47
}
32
48
}
33
49
@@ -36,26 +52,30 @@ impl<'a> ParamDef<'a> {
36
52
Self { name }
37
53
}
38
54
39
- pub fn value ( & self , value : & ' a Value ) -> Param < ' a > {
55
+ pub fn value < T : Into < Value > > ( & self , value : T ) -> Param < ' a > {
40
56
Param {
41
57
name : self . name ,
42
- value : value,
58
+ value : value. into ( ) ,
43
59
}
44
60
}
61
+
62
+ //pub fn value_ref(&self, value: &'a Value) -> Param<'a> {
63
+ // Param {
64
+ // name: self.name,
65
+ // value: Cow::Borrowed(value),
66
+ // }
67
+ //}
45
68
}
46
69
47
70
impl < ' a > Query < ' a > {
48
71
pub fn new ( query : & ' a str ) -> Self {
49
- Self {
50
- query,
51
- parameters : vec ! [ ] ,
52
- }
72
+ Self :: with_params ( query, vec ! [ ] )
53
73
}
54
74
55
- pub fn with_params ( query : & ' a str , params : Vec < Param < ' a > > ) -> Self {
75
+ pub fn with_params < T : Into < Vec < Param < ' a > > > > ( query : & ' a str , params : T ) -> Self {
56
76
Self {
57
77
query,
58
- parameters : params,
78
+ parameters : params. into ( ) ,
59
79
}
60
80
}
61
81
@@ -92,9 +112,9 @@ mod tests {
92
112
let query = Query :: with_params (
93
113
"SELECT * FROM t" ,
94
114
vec ! [
95
- p1. value( & Value :: from ( "string" ) ) ,
96
- Param :: new( "p2" , & Value :: from ( 100u64 ) ) ,
97
- Param :: new( "p3" , & v3) ,
115
+ p1. value( "string" ) ,
116
+ Param :: new( "p2" , 100u64 ) ,
117
+ Param :: new( "p3" , v3) ,
98
118
] ,
99
119
) ;
100
120
0 commit comments