Skip to content

Commit f50dfa8

Browse files
bmc-msftdemoray
andauthored
Move get blob to pageable (#850)
* initial work to extend Pageable to support more than just * cleanup debugging * cleanup test * fmt * use From instead of Into * address clippy * address comments to be clearer * address feedback * fix issue from refactor * update generator to support new Continuation * regenerate services using the updated Continuation support Co-authored-by: Brian Caswell <[email protected]>
1 parent 9e76b2d commit f50dfa8

File tree

1,410 files changed

+50886
-27909
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,410 files changed

+50886
-27909
lines changed

sdk/core/src/pageable.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,12 @@ where
4242
r#try!(request.await)
4343
}
4444
State::Continuation(token) => {
45-
let request = make_request(Some(Continuation::new(token)));
45+
let request = make_request(Some(token));
4646
r#try!(request.await)
4747
}
48-
State::Done => return None,
48+
State::Done => {
49+
return None;
50+
}
4951
};
5052

5153
let next_state = response
@@ -82,12 +84,12 @@ impl<T, O> std::fmt::Debug for Pageable<T, O> {
8284

8385
/// A type that can yield an optional continuation token
8486
pub trait Continuable {
85-
fn continuation(&self) -> Option<String>;
87+
fn continuation(&self) -> Option<Continuation>;
8688
}
8789

8890
#[derive(Debug, Clone, PartialEq)]
8991
enum State {
9092
Init,
91-
Continuation(String),
93+
Continuation(Continuation),
9294
Done,
9395
}
Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,50 @@
1-
use crate::{headers, Header};
1+
use crate::{headers, request_options::NextMarker, request_options::Range, Header};
2+
use std::ops::Range as StdRange;
23

3-
#[derive(Debug, Clone)]
4-
pub struct Continuation(String);
4+
#[derive(Debug, Clone, PartialEq, Eq)]
5+
pub enum Continuation {
6+
String(String),
7+
Range(StdRange<u64>),
8+
}
59

6-
impl Continuation {
7-
pub fn new(c: String) -> Self {
8-
Self(c)
10+
impl From<NextMarker> for Continuation {
11+
fn from(next_marker: NextMarker) -> Self {
12+
Continuation::String(next_marker.as_str().to_string())
13+
}
14+
}
15+
16+
impl From<&str> for Continuation {
17+
fn from(value: &str) -> Self {
18+
Continuation::String(value.to_string())
19+
}
20+
}
21+
22+
impl From<String> for Continuation {
23+
fn from(value: String) -> Self {
24+
Continuation::String(value)
925
}
26+
}
27+
28+
impl From<StdRange<u64>> for Continuation {
29+
fn from(value: StdRange<u64>) -> Self {
30+
Continuation::Range(value)
31+
}
32+
}
1033

11-
pub fn into_raw(self) -> String {
12-
self.0
34+
impl From<Range> for Continuation {
35+
fn from(value: Range) -> Self {
36+
Continuation::Range(value.start..value.end)
37+
}
38+
}
39+
40+
impl Continuation {
41+
pub fn as_string(&self) -> String {
42+
match self {
43+
Self::String(c) => c.clone(),
44+
Self::Range(_) => {
45+
panic!("unable to convert Continuation::Range to string")
46+
}
47+
}
1348
}
1449
}
1550

@@ -19,6 +54,6 @@ impl Header for Continuation {
1954
}
2055

2156
fn value(&self) -> headers::HeaderValue {
22-
self.0.to_owned().into()
57+
self.as_string().into()
2358
}
2459
}

sdk/core/src/request_options/next_marker.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ impl AppendToUrlQuery for NextMarker {
4848

4949
impl From<Continuation> for NextMarker {
5050
fn from(next_marker: Continuation) -> Self {
51-
Self::new(next_marker.into_raw())
51+
Self::new(next_marker.as_string())
5252
}
5353
}
5454

sdk/data_cosmos/src/operations/list_attachments.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ impl ListAttachmentsResponse {
160160
}
161161

162162
impl Continuable for ListAttachmentsResponse {
163-
fn continuation(&self) -> Option<String> {
164-
self.continuation_token.clone()
163+
fn continuation(&self) -> Option<Continuation> {
164+
self.continuation_token.clone().map(Continuation::from)
165165
}
166166
}

sdk/data_cosmos/src/operations/list_collections.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ impl ListCollectionsResponse {
116116
}
117117

118118
impl Continuable for ListCollectionsResponse {
119-
fn continuation(&self) -> Option<String> {
120-
self.continuation_token.clone()
119+
fn continuation(&self) -> Option<Continuation> {
120+
self.continuation_token.clone().map(Continuation::from)
121121
}
122122
}

sdk/data_cosmos/src/operations/list_databases.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ impl ListDatabasesResponse {
112112
}
113113

114114
impl Continuable for ListDatabasesResponse {
115-
fn continuation(&self) -> Option<String> {
116-
self.continuation_token.clone()
115+
fn continuation(&self) -> Option<Continuation> {
116+
self.continuation_token.clone().map(Continuation::from)
117117
}
118118
}
119119

sdk/data_cosmos/src/operations/list_documents.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,8 @@ where
192192
}
193193

194194
impl<T> Continuable for ListDocumentsResponse<T> {
195-
fn continuation(&self) -> Option<String> {
196-
self.continuation_token.clone()
195+
fn continuation(&self) -> Option<Continuation> {
196+
self.continuation_token.clone().map(Continuation::from)
197197
}
198198
}
199199

sdk/data_cosmos/src/operations/list_permissions.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ impl ListPermissionsResponse {
107107
}
108108

109109
impl Continuable for ListPermissionsResponse {
110-
fn continuation(&self) -> Option<String> {
111-
self.continuation_token.clone()
110+
fn continuation(&self) -> Option<Continuation> {
111+
self.continuation_token.clone().map(Continuation::from)
112112
}
113113
}

sdk/data_cosmos/src/operations/list_stored_procedures.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ impl ListStoredProceduresResponse {
113113
}
114114

115115
impl Continuable for ListStoredProceduresResponse {
116-
fn continuation(&self) -> Option<String> {
117-
self.continuation_token.clone()
116+
fn continuation(&self) -> Option<Continuation> {
117+
self.continuation_token.clone().map(Continuation::from)
118118
}
119119
}

sdk/data_cosmos/src/operations/list_triggers.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ impl ListTriggersResponse {
149149
}
150150

151151
impl Continuable for ListTriggersResponse {
152-
fn continuation(&self) -> Option<String> {
153-
self.continuation_token.clone()
152+
fn continuation(&self) -> Option<Continuation> {
153+
self.continuation_token.clone().map(Continuation::from)
154154
}
155155
}

0 commit comments

Comments
 (0)