@@ -4,22 +4,21 @@ use serde::{Deserialize, Serialize};
4
4
// DB.
5
5
use azure_core:: prelude:: * ;
6
6
use azure_data_cosmos:: prelude:: * ;
7
- use std:: borrow:: Cow ;
8
7
use std:: error:: Error ;
9
8
10
9
#[ derive( Clone , Serialize , Deserialize , Debug ) ]
11
- struct MySampleStruct < ' a > {
12
- id : Cow < ' a , str > ,
13
- a_string : Cow < ' a , str > ,
10
+ struct MySampleStruct {
11
+ id : String ,
12
+ a_string : String ,
14
13
a_number : u64 ,
15
14
a_timestamp : i64 ,
16
15
}
17
16
18
- impl < ' a > azure_data_cosmos:: CosmosEntity < ' a > for MySampleStruct < ' a > {
19
- type Entity = & ' a str ;
17
+ impl azure_data_cosmos:: CosmosEntity for MySampleStruct {
18
+ type Entity = String ;
20
19
21
- fn partition_key ( & ' a self ) -> Self :: Entity {
22
- self . id . as_ref ( )
20
+ fn partition_key ( & self ) -> Self :: Entity {
21
+ self . id . clone ( )
23
22
}
24
23
}
25
24
@@ -102,11 +101,8 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
102
101
client
103
102
. clone ( )
104
103
. into_database_client ( database. id . clone ( ) )
105
- . create_collection (
106
- Context :: new ( ) ,
107
- COLLECTION ,
108
- CreateCollectionOptions :: new ( "/id" ) ,
109
- )
104
+ . create_collection ( COLLECTION , "/id" )
105
+ . into_future ( )
110
106
. await ?
111
107
. collection
112
108
}
@@ -118,8 +114,8 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
118
114
// data in them. Let's create a Document. The only constraint
119
115
// is that we need an id and an arbitrary, Serializable type.
120
116
let doc = MySampleStruct {
121
- id : Cow :: Owned ( "unique_id100" . to_owned ( ) ) ,
122
- a_string : Cow :: Borrowed ( "Something here" ) ,
117
+ id : "unique_id100" . into ( ) ,
118
+ a_string : "Something here" . into ( ) ,
123
119
a_number : 100 ,
124
120
a_timestamp : chrono:: Utc :: now ( ) . timestamp ( ) ,
125
121
} ;
@@ -135,7 +131,8 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
135
131
// the document attributes.
136
132
137
133
let create_document_response = collection_client
138
- . create_document ( Context :: new ( ) , & doc, CreateDocumentOptions :: new ( ) )
134
+ . create_document ( doc. clone ( ) )
135
+ . into_future ( )
139
136
. await ?;
140
137
println ! (
141
138
"create_document_response == {:#?}" ,
@@ -191,14 +188,16 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
191
188
. clone ( )
192
189
. into_database_client ( DATABASE . to_owned ( ) )
193
190
. into_collection_client ( COLLECTION . to_owned ( ) )
194
- . delete_collection ( Context :: new ( ) , DeleteCollectionOptions :: new ( ) )
191
+ . delete_collection ( )
192
+ . into_future ( )
195
193
. await ?;
196
194
println ! ( "collection deleted" ) ;
197
195
198
196
// And then we delete the database.
199
197
client
200
198
. into_database_client ( database. id )
201
- . delete_database ( Context :: new ( ) , DeleteDatabaseOptions :: new ( ) )
199
+ . delete_database ( )
200
+ . into_future ( )
202
201
. await ?;
203
202
println ! ( "database deleted" ) ;
204
203
0 commit comments