Skip to content
This repository was archived by the owner on Oct 6, 2020. It is now read-only.

Commit 559b0fe

Browse files
committed
workaround for bug rust-lang/rust#63033
1 parent f276e97 commit 559b0fe

File tree

1 file changed

+37
-17
lines changed

1 file changed

+37
-17
lines changed

azure_sdk_cosmos/src/query.rs

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
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)]
410
pub struct Query<'a> {
511
query: &'a str,
612
parameters: Vec<Param<'a>>,
@@ -9,7 +15,7 @@ pub struct Query<'a> {
915
#[derive(Debug, Serialize, Clone)]
1016
pub struct Param<'a> {
1117
name: &'a str,
12-
value: &'a Value,
18+
value: Value,
1319
}
1420

1521
#[derive(Debug, Serialize, Clone)]
@@ -18,16 +24,26 @@ pub struct ParamDef<'a> {
1824
}
1925

2026
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+
}
2332
}
2433

34+
//pub fn new_ref(name: &'a str, value: &'a Value) -> Self {
35+
// Self {
36+
// name,
37+
// value: Cow::Borrowed(value),
38+
// }
39+
//}
40+
2541
pub fn name(&self) -> &'a str {
2642
self.name
2743
}
2844

2945
pub fn value(&self) -> &Value {
30-
self.value
46+
&self.value
3147
}
3248
}
3349

@@ -36,26 +52,30 @@ impl<'a> ParamDef<'a> {
3652
Self { name }
3753
}
3854

39-
pub fn value(&self, value: &'a Value) -> Param<'a> {
55+
pub fn value<T: Into<Value>>(&self, value: T) -> Param<'a> {
4056
Param {
4157
name: self.name,
42-
value: value,
58+
value: value.into(),
4359
}
4460
}
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+
//}
4568
}
4669

4770
impl<'a> Query<'a> {
4871
pub fn new(query: &'a str) -> Self {
49-
Self {
50-
query,
51-
parameters: vec![],
52-
}
72+
Self::with_params(query, vec![])
5373
}
5474

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 {
5676
Self {
5777
query,
58-
parameters: params,
78+
parameters: params.into(),
5979
}
6080
}
6181

@@ -92,9 +112,9 @@ mod tests {
92112
let query = Query::with_params(
93113
"SELECT * FROM t",
94114
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),
98118
],
99119
);
100120

0 commit comments

Comments
 (0)