Skip to content

Commit 15de10c

Browse files
authored
into_future again (#670)
* ListDocuments::into_stream * ListPermissions::into_stream * DeleteStoredProcedure::into_future * fmt * ListAttachments::into_stream
1 parent 14a2f03 commit 15de10c

36 files changed

+586
-709
lines changed

sdk/data_cosmos/examples/attachments_00.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use azure_data_cosmos::prelude::*;
2+
use futures::StreamExt;
23
use serde::{Deserialize, Serialize};
34
use std::error::Error;
45

@@ -62,7 +63,12 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
6263
let document_client = client.into_document_client(doc.id.clone(), &doc.id)?;
6364

6465
// list attachments
65-
let ret = document_client.list_attachments().execute().await?;
66+
let ret = document_client
67+
.list_attachments()
68+
.into_stream()
69+
.next()
70+
.await
71+
.unwrap()?;
6672
println!("list attachments == {:#?}", ret);
6773

6874
// reference attachment

sdk/data_cosmos/examples/database_00.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,10 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
8080

8181
let documents = collection_client
8282
.list_documents()
83-
.execute::<Value>()
84-
.await?;
83+
.into_stream::<Value>()
84+
.next()
85+
.await
86+
.unwrap()?;
8587
println!("\ndocuments as json == {:?}", documents);
8688
}
8789
}

sdk/data_cosmos/examples/document_00.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,10 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
145145
println!("Listing documents...");
146146
let list_documents_response = collection_client
147147
.list_documents()
148-
.execute::<MySampleStruct>()
149-
.await?;
148+
.into_stream::<MySampleStruct>()
149+
.next()
150+
.await
151+
.unwrap()?;
150152
println!(
151153
"list_documents_response contains {} documents",
152154
list_documents_response.documents.len()

sdk/data_cosmos/examples/document_entries_00.rs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,13 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
5858
println!("Created 5 documents.");
5959

6060
// Let's get 3 entries at a time.
61-
let response = client
61+
let mut paged = client
6262
.list_documents()
6363
.consistency_level(response.unwrap())
6464
.max_item_count(3i32)
65-
.execute::<MySampleStruct>()
66-
.await?;
65+
.into_stream::<MySampleStruct>();
66+
67+
let response = paged.next().await.unwrap()?;
6768

6869
assert_eq!(response.documents.len(), 3);
6970
println!("response == {:#?}", response);
@@ -72,16 +73,7 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
7273
// continuation_token must be present
7374
assert!(response.continuation_token.is_some());
7475

75-
let session_token = &response;
76-
let ct = response.continuation_token.clone().unwrap();
77-
println!("ct == {}", ct);
78-
79-
let response = client
80-
.list_documents()
81-
.consistency_level(session_token)
82-
.continuation(ct.as_str())
83-
.execute::<MySampleStruct>()
84-
.await?;
76+
let response = paged.next().await.unwrap()?;
8577

8678
assert_eq!(response.documents.len(), 2);
8779
println!("response == {:#?}", response);
@@ -101,7 +93,7 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
10193
.list_documents()
10294
.consistency_level(session_token.clone())
10395
.max_item_count(3);
104-
let mut stream = Box::pin(stream.stream::<MySampleStruct>());
96+
let mut stream = stream.into_stream::<MySampleStruct>();
10597
// TODO: As soon as the streaming functionality is completed
10698
// in Rust substitute this while let Some... into
10799
// for each (or whatever the Rust team picks).

sdk/data_cosmos/examples/document_entries_01.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use azure_data_cosmos::prelude::*;
2+
use futures::StreamExt;
23
use serde::{Deserialize, Serialize};
34
use std::error::Error;
45

@@ -82,8 +83,10 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
8283
let list_documents_response = client
8384
.list_documents()
8485
.consistency_level(&get_document_response)
85-
.execute::<serde_json::Value>()
86-
.await?;
86+
.into_stream::<serde_json::Value>()
87+
.next()
88+
.await
89+
.unwrap()?;
8790
println!("list_documents_response == {:#?}", list_documents_response);
8891

8992
let query_documents_response = client

sdk/data_cosmos/examples/permission_00.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use azure_data_cosmos::prelude::*;
2+
use futures::StreamExt;
23
use std::error::Error;
34

45
#[tokio::main]
@@ -92,8 +93,10 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
9293
.consistency_level(ConsistencyLevel::Session(
9394
create_permission2_response.session_token,
9495
))
95-
.execute()
96-
.await?;
96+
.into_stream()
97+
.next()
98+
.await
99+
.unwrap()?;
97100
println!(
98101
"list_permissions_response == {:#?}",
99102
list_permissions_response

sdk/data_cosmos/examples/readme.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
9999
.list_documents()
100100
.consistency_level(session_token.clone())
101101
.max_item_count(3);
102-
let mut stream = Box::pin(stream.stream::<MySampleStruct>());
102+
let mut stream = stream.into_stream::<MySampleStruct>();
103103
// TODO: As soon as the streaming functionality is stabilized
104104
// in Rust we can substitute this while let Some... into
105105
// for each (or whatever the Rust team picks).
@@ -158,8 +158,10 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
158158
let list_documents_response = collection_client
159159
.list_documents()
160160
.consistency_level(session_token)
161-
.execute::<serde_json::Value>() // you can use this if you don't know/care about the return type!
162-
.await?;
161+
.into_stream::<serde_json::Value>() // you can use this if you don't know/care about the return type!
162+
.next()
163+
.await
164+
.unwrap()?;
163165
assert_eq!(list_documents_response.documents.len(), 4);
164166

165167
Ok(())

sdk/data_cosmos/examples/remove_all_documents.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
3636
let mut documents = Vec::new();
3737

3838
let stream = client.list_documents();
39-
let mut stream = Box::pin(stream.stream::<serde_json::Value>());
39+
let mut stream = stream.into_stream::<serde_json::Value>();
4040
while let Some(res) = stream.next().await {
4141
for doc in res?.documents {
4242
documents.push(doc);

sdk/data_cosmos/examples/stored_proc_01.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
7979

8080
let delete_stored_procedure_response = stored_procedure_client
8181
.delete_stored_procedure()
82-
.execute()
82+
.into_future()
8383
.await?;
8484
println!(
8585
"delete_stored_procedure_response == {:#?}",

sdk/data_cosmos/examples/user_permission_token.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use azure_data_cosmos::prelude::*;
2+
use futures::StreamExt;
23
use std::error::Error;
34

45
#[tokio::main]
@@ -42,9 +43,10 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
4243
// test list documents
4344
let list_documents_response = collection_client
4445
.list_documents()
45-
.execute::<serde_json::Value>()
46+
.into_stream::<serde_json::Value>()
47+
.next()
4648
.await
47-
.unwrap();
49+
.unwrap()?;
4850
println!(
4951
"list_documents_response got {} document(s).",
5052
list_documents_response.documents.len()
@@ -86,9 +88,10 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
8688
.into_database_client(database_name.clone())
8789
.into_collection_client(collection_name.clone())
8890
.list_documents()
89-
.execute::<serde_json::Value>()
91+
.into_stream::<serde_json::Value>()
92+
.next()
9093
.await
91-
.unwrap();
94+
.unwrap()?;
9295
println!(
9396
"second list_documents_response got {} document(s).",
9497
list_documents_response.documents.len()

0 commit comments

Comments
 (0)