@@ -3,25 +3,24 @@ use serde::{Deserialize, Serialize};
33// Using the prelude module of the Cosmos crate makes easier to use the Rust Azure SDK for Cosmos.
44use azure_data_cosmos:: prelude:: * ;
55use futures:: stream:: StreamExt ;
6- use std:: borrow:: Cow ;
76use std:: error:: Error ;
87
98// This is the stuct we want to use in our sample.
109// Make sure to have a collection with partition key "a_number" for this example to
1110// work (you can create with this SDK too, check the examples folder for that task).
12- #[ derive( Serialize , Deserialize , Debug ) ]
13- struct MySampleStruct < ' a > {
14- id : Cow < ' a , str > ,
15- a_string : Cow < ' a , str > ,
11+ #[ derive( Serialize , Deserialize , Debug , Clone ) ]
12+ struct MySampleStruct {
13+ id : String ,
14+ a_string : String ,
1615 a_number : u64 ,
1716 a_timestamp : i64 ,
1817}
1918
2019// Here we mark "a_number" as partition key.
21- impl < ' a > azure_data_cosmos:: CosmosEntity < ' a > for MySampleStruct < ' a > {
20+ impl azure_data_cosmos:: CosmosEntity for MySampleStruct {
2221 type Entity = u64 ;
2322
24- fn partition_key ( & ' a self ) -> Self :: Entity {
23+ fn partition_key ( & self ) -> Self :: Entity {
2524 self . a_number
2625 }
2726}
@@ -71,20 +70,18 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
7170 for i in 0 ..10 {
7271 // define the document.
7372 let document_to_insert = MySampleStruct {
74- id : Cow :: Owned ( format ! ( "unique_id{}" , i) ) ,
75- a_string : Cow :: Borrowed ( "Something here" ) ,
73+ id : format ! ( "unique_id{}" , i) ,
74+ a_string : "Something here" . into ( ) ,
7675 a_number : i * 100 , // this is the partition key
7776 a_timestamp : chrono:: Utc :: now ( ) . timestamp ( ) ,
7877 } ;
7978
8079 // insert it and store the returned session token for later use!
8180 session_token = Some (
8281 collection_client
83- . create_document (
84- Context :: new ( ) ,
85- & document_to_insert,
86- CreateDocumentOptions :: new ( ) . is_upsert ( true ) ,
87- )
82+ . create_document ( document_to_insert. clone ( ) )
83+ . is_upsert ( true )
84+ . into_future ( )
8885 . await ?
8986 . session_token , // get only the session token, if everything else was ok!
9087 ) ;
0 commit comments