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

Commit 9e25125

Browse files
committed
Fixed type mismatch using multiple AsRef
1 parent 6903bf9 commit 9e25125

File tree

9 files changed

+84
-51
lines changed

9 files changed

+84
-51
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
## [0.4.2](https://github.com/MindFlavor/AzureSDKForRust/releases/tag/0.4.2) (2017-07-05)
2+
3+
**Bugfix:**
4+
5+
* Corrected a type mistake in multiple ```AsRef<str>``` parameters.
6+
* Implemented ```AsRef<str>``` in Cosmos document and collection.
7+
* Fixed type mismatch in examples (in README.md too).
8+
19
## [0.4.1](https://github.com/MindFlavor/AzureSDKForRust/releases/tag/0.4.1) (2017-07-05)
210

311
**Implemented features:**

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "azure_sdk_for_rust"
3-
version = "0.4.1"
3+
version = "0.4.2"
44
description = "Rust wrappers around Microsoft Azure REST APIs"
55
readme = "README.md"
66
authors = ["Francesco Cogno <[email protected]>", "Dong Liu <[email protected]>"]

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44

55
[![Crate](https://img.shields.io/crates/v/azure_sdk_for_rust.svg)](https://crates.io/crates/azure_sdk_for_rust) [![legal](https://img.shields.io/crates/l/azure_sdk_for_rust.svg)](LICENSE) [![cratedown](https://img.shields.io/crates/d/azure_sdk_for_rust.svg)](https://crates.io/crates/azure_sdk_for_rust) [![cratelastdown](https://img.shields.io/crates/dv/azure_sdk_for_rust.svg)](https://crates.io/crates/azure_sdk_for_rust)
66

7-
[![tag](https://img.shields.io/github/tag/mindflavor/AzureSDKForRust.svg)](https://github.com/MindFlavor/AzureSDKForRust/tree/0.4.1)
8-
[![release](https://img.shields.io/github/release/mindflavor/AzureSDKForRust.svg)](https://github.com/MindFlavor/AzureSDKForRust/tree/0.4.1)
9-
[![commitssince](https://img.shields.io/github/commits-since/mindflavor/AzureSDKForRust/0.4.1.svg)](https://img.shields.io/github/commits-since/mindflavor/AzureSDKForRust/0.4.1.svg)
7+
[![tag](https://img.shields.io/github/tag/mindflavor/AzureSDKForRust.svg)](https://github.com/MindFlavor/AzureSDKForRust/tree/0.4.2)
8+
[![release](https://img.shields.io/github/release/mindflavor/AzureSDKForRust.svg)](https://github.com/MindFlavor/AzureSDKForRust/tree/0.4.2)
9+
[![commitssince](https://img.shields.io/github/commits-since/mindflavor/AzureSDKForRust/0.4.2.svg)](https://img.shields.io/github/commits-since/mindflavor/AzureSDKForRust/0.4.2.svg)
1010

1111
## Introduction
1212
Microsoft Azure expose its technologies via REST API. These APIs are easily consumable from any language (good) but are weakly typed. With this library and its related [crate](https://crates.io/crates/azure_sdk_for_rust/) you can exploit the power of Microsoft Azure from Rust in a idiomatic way.
1313

14-
This crate relies heavily on the excellent crate called [Hyper](https://github.com/hyperium/hyper). As of this library version [0.4.1](https://github.com/MindFlavor/AzureSDKForRust/releases/tag/0.4.1) all the methods are future-aware. That is, I'm using the latest Hyper code.
14+
This crate relies heavily on the excellent crate called [Hyper](https://github.com/hyperium/hyper). As of this library version [0.4.2](https://github.com/MindFlavor/AzureSDKForRust/releases/tag/0.4.2) all the methods are future-aware. That is, I'm using the latest Hyper code.
1515

1616
Rust, however, still requires you to Box every future returned by a method. The alternative is to use the ```impl Trait``` feature which is nightly-only. Since I've used it everywhere this library will require a nightly Rust compiler until the ```impl Trait``` makes its way to the stable channel. Also since I'm using an unstable feature these is a very good chance of this code to break in the future.
1717

@@ -163,7 +163,7 @@ fn code() -> Result<(), Box<Error>> {
163163
// The method create_document will return, upon success,
164164
// the document attributes.
165165
let document_attributes = core.run(
166-
client.create_document(&database, &collection, false, None, &doc),
166+
client.create_document_as_entity(&database, &collection, false, None, &doc),
167167
)?;
168168
println!("document_attributes == {:?}", document_attributes);
169169

examples/document00.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ fn code() -> Result<(), Box<Error>> {
134134
// The method create_document will return, upon success,
135135
// the document attributes.
136136
let document_attributes = core.run(
137-
client.create_document(&database, &collection, false, None, &doc),
137+
client.create_document_as_entity(&database, &collection, false, None, &doc),
138138
)?;
139139
println!("document_attributes == {:?}", document_attributes);
140140

examples/document_entries00.rs

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -72,18 +72,26 @@ fn code() -> Result<(), Box<Error>> {
7272
a_timestamp: chrono::Utc::now().timestamp(),
7373
};
7474

75-
println!("Adding one entity");
76-
core.run(
75+
// let's add an entity. we ignore the errors at this point and just
76+
// notify the user.
77+
match core.run(
7778
client.create_document_as_entity(&database_name, &collection_name, false, None, &doc),
78-
);
79+
) {
80+
Ok(_) => {
81+
println!("entity added");
82+
}
83+
Err(error) => {
84+
println!("entity add failed (maybe already there?) {:?}", error);
85+
}
86+
};
7987
}
8088

8189
// let's get 3 entries at a time
8290
let mut ldo = LIST_DOCUMENTS_OPTIONS_DEFAULT.clone();
8391
ldo.max_item_count = Some(3);
8492

8593
let (entries, ldah) = core.run(
86-
client.list_documents::<_, MySampleStructOwned>(&database_name, &collection_name, &ldo),
94+
client.list_documents::<_, _, MySampleStructOwned>(&database_name, &collection_name, &ldo),
8795
).unwrap();
8896

8997
assert_eq!(entries.documents.len(), 3);
@@ -98,9 +106,14 @@ fn code() -> Result<(), Box<Error>> {
98106
let mut ldo = LIST_DOCUMENTS_OPTIONS_DEFAULT.clone();
99107
ldo.continuation_token = Some(&ct);
100108

101-
let (entries, ldah) = core.run(
102-
client.list_documents::<_, MySampleStructOwned>(&database_name, &collection_name, &ldo),
103-
).unwrap();
109+
let (entries, ldah) =
110+
core.run(
111+
client.list_documents::<_, _, MySampleStructOwned>(
112+
&database_name,
113+
&collection_name,
114+
&ldo,
115+
),
116+
).unwrap();
104117

105118
assert_eq!(entries.documents.len(), 2);
106119
println!("entries == {:?}\nldah = {:?}", entries, ldah);
@@ -112,31 +125,25 @@ fn code() -> Result<(), Box<Error>> {
112125
let gdo = GET_DOCUMENT_OPTIONS_DEFAULT.clone();
113126
let id = format!("unique_id{}", 3);
114127

115-
let (entry, gdah) =
116-
core.run(
117-
client.get_document::<_, MySampleStructOwned>(
118-
&database_name,
119-
&collection_name,
120-
&id,
121-
&gdo,
122-
),
123-
).unwrap();
128+
let (entry, gdah) = core.run(client.get_document::<_, _, _, MySampleStructOwned>(
129+
&database_name,
130+
&collection_name,
131+
&id,
132+
&gdo,
133+
)).unwrap();
124134

125135
assert_eq!(entry.is_some(), true);
126136
println!("entry == {:?}\ngdah == {:?}", entry, gdah);
127137

128138
// This id should not be found. We expect None as result
129139
let id = format!("unique_id{}", 100);
130140

131-
let (entry, gdah) =
132-
core.run(
133-
client.get_document::<_, MySampleStructOwned>(
134-
&database_name,
135-
&collection_name,
136-
&id,
137-
&gdo,
138-
),
139-
).unwrap();
141+
let (entry, gdah) = core.run(client.get_document::<_, _, _, MySampleStructOwned>(
142+
&database_name,
143+
&collection_name,
144+
&id,
145+
&gdo,
146+
)).unwrap();
140147

141148
assert_eq!(entry.is_some(), false);
142149
println!("entry == {:?}\ngdah == {:?}", entry, gdah);

src/azure/cosmos/client.rs

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -576,17 +576,19 @@ impl<'a> Client {
576576
)
577577
}
578578

579-
pub fn create_document_as_str<T, S>(
579+
pub fn create_document_as_str<T, S1, S2, S3>(
580580
&self,
581-
database: S,
582-
collection: S,
581+
database: S1,
582+
collection: S2,
583583
is_upsert: bool,
584584
indexing_directive: Option<IndexingDirective>,
585-
document_str: S,
585+
document_str: S3,
586586
) -> impl Future<Item = DocumentAttributes, Error = AzureError>
587587
where
588588
T: Serialize,
589-
S: AsRef<str>,
589+
S1: AsRef<str>,
590+
S2: AsRef<str>,
591+
S3: AsRef<str>,
590592
{
591593
let database = database.as_ref();
592594
let collection = collection.as_ref();
@@ -613,17 +615,18 @@ impl<'a> Client {
613615
})
614616
}
615617

616-
pub fn create_document_as_entity<T, S>(
618+
pub fn create_document_as_entity<T, S1, S2>(
617619
&self,
618-
database: S,
619-
collection: S,
620+
database: S1,
621+
collection: S2,
620622
is_upsert: bool,
621623
indexing_directive: Option<IndexingDirective>,
622624
document: &T,
623625
) -> impl Future<Item = DocumentAttributes, Error = AzureError>
624626
where
625627
T: Serialize,
626-
S: AsRef<str>,
628+
S1: AsRef<str>,
629+
S2: AsRef<str>,
627630
{
628631
let database = database.as_ref();
629632
let collection = collection.as_ref();
@@ -700,10 +703,10 @@ impl<'a> Client {
700703
}
701704

702705

703-
pub fn list_documents<'b, S, T>(
706+
pub fn list_documents<'b, S1, S2, T>(
704707
&self,
705-
database: S,
706-
collection: S,
708+
database: S1,
709+
collection: S2,
707710
ldo: &ListDocumentsOptions,
708711
) -> impl Future<
709712
Item = (
@@ -713,7 +716,8 @@ impl<'a> Client {
713716
Error = AzureError,
714717
>
715718
where
716-
S: AsRef<str>,
719+
S1: AsRef<str>,
720+
S2: AsRef<str>,
717721
T: DeserializeOwned,
718722
{
719723
let database = database.as_ref();
@@ -809,15 +813,17 @@ impl<'a> Client {
809813
Ok(self.hyper_client.request(request))
810814
}
811815

812-
pub fn get_document<S, T>(
816+
pub fn get_document<S1, S2, S3, T>(
813817
&self,
814-
database: S,
815-
collection: S,
816-
document_id: S,
818+
database: S1,
819+
collection: S2,
820+
document_id: S3,
817821
gdo: &GetDocumentOptions,
818822
) -> impl Future<Item = (Option<Document<T>>, GetDocumentAdditionalHeaders), Error = AzureError>
819823
where
820-
S: AsRef<str>,
824+
S1: AsRef<str>,
825+
S2: AsRef<str>,
826+
S3: AsRef<str>,
821827
T: DeserializeOwned,
822828
{
823829
let database = database.as_ref();

src/azure/cosmos/collection.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,9 @@ impl Deref for Collection {
121121
&self.id
122122
}
123123
}
124+
125+
impl AsRef<str> for Collection {
126+
fn as_ref(&self) -> &str {
127+
&self.id
128+
}
129+
}

src/azure/cosmos/database.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,9 @@ impl Deref for Database {
2424
&self.id
2525
}
2626
}
27+
28+
impl AsRef<str> for Database {
29+
fn as_ref(&self) -> &str {
30+
&self.id
31+
}
32+
}

0 commit comments

Comments
 (0)