unitycatalog_client/codegen/shares/
builders.rs1#![allow(unused_mut)]
3#![allow(unused_imports)]
4#[cfg(not(target_arch = "wasm32"))]
5type BoxFut<'a, T> = ::futures::future::BoxFuture<'a, T>;
6#[cfg(target_arch = "wasm32")]
7type BoxFut<'a, T> = ::futures::future::LocalBoxFuture<'a, T>;
8#[cfg(not(target_arch = "wasm32"))]
9type BoxStr<'a, T> = ::futures::stream::BoxStream<'a, T>;
10#[cfg(target_arch = "wasm32")]
11type BoxStr<'a, T> = ::futures::stream::LocalBoxStream<'a, T>;
12use super::super::stream_paginated;
13use super::client::*;
14use crate::Result;
15use futures::{StreamExt, TryStreamExt};
16use std::future::IntoFuture;
17use unitycatalog_common::models::shares::v1::*;
18pub struct ListSharesBuilder {
20 client: ShareServiceClient,
21 request: ListSharesRequest,
22}
23impl ListSharesBuilder {
24 pub(crate) fn new(client: ShareServiceClient) -> Self {
27 let request = ListSharesRequest {
28 ..Default::default()
29 };
30 Self { client, request }
31 }
32 pub fn with_max_results(mut self, max_results: impl Into<Option<i32>>) -> Self {
34 self.request.max_results = max_results.into();
35 self
36 }
37 pub fn with_page_token(mut self, page_token: impl Into<Option<String>>) -> Self {
39 self.request.page_token = page_token.into();
40 self
41 }
42 pub fn into_stream(self) -> BoxStr<'static, Result<Share>> {
44 let remaining = self.request.max_results;
45 let stream = stream_paginated(
46 (self, remaining),
47 move |(mut builder, mut remaining), page_token| async move {
48 builder.request.page_token = page_token;
49 let res = builder.client.list_shares(&builder.request).await?;
50 if let Some(ref mut rem) = remaining {
51 *rem -= res.shares.len() as i32;
52 }
53 let next_page_token = if remaining.is_some_and(|r| r <= 0) {
54 None
55 } else {
56 res.next_page_token.clone()
57 };
58 Ok((res, (builder, remaining), next_page_token))
59 },
60 )
61 .map_ok(|resp| futures::stream::iter(resp.shares.into_iter().map(Ok)))
62 .try_flatten();
63 #[cfg(not(target_arch = "wasm32"))]
64 let stream = stream.boxed();
65 #[cfg(target_arch = "wasm32")]
66 let stream = stream.boxed_local();
67 stream
68 }
69}
70impl IntoFuture for ListSharesBuilder {
71 type Output = Result<ListSharesResponse>;
72 type IntoFuture = BoxFut<'static, Self::Output>;
73 fn into_future(self) -> Self::IntoFuture {
74 let client = self.client;
75 let request = self.request;
76 Box::pin(async move { client.list_shares(&request).await })
77 }
78}
79pub struct CreateShareBuilder {
81 client: ShareServiceClient,
82 request: CreateShareRequest,
83}
84impl CreateShareBuilder {
85 pub(crate) fn new(client: ShareServiceClient, name: impl Into<String>) -> Self {
88 let request = CreateShareRequest {
89 name: name.into(),
90 ..Default::default()
91 };
92 Self { client, request }
93 }
94 pub fn with_comment(mut self, comment: impl Into<Option<String>>) -> Self {
96 self.request.comment = comment.into();
97 self
98 }
99}
100impl IntoFuture for CreateShareBuilder {
101 type Output = Result<Share>;
102 type IntoFuture = BoxFut<'static, Self::Output>;
103 fn into_future(self) -> Self::IntoFuture {
104 let client = self.client;
105 let request = self.request;
106 Box::pin(async move { client.create_share(&request).await })
107 }
108}
109pub struct GetShareBuilder {
111 client: ShareServiceClient,
112 request: GetShareRequest,
113}
114impl GetShareBuilder {
115 pub(crate) fn new(client: ShareServiceClient, name: impl Into<String>) -> Self {
118 let request = GetShareRequest {
119 name: name.into(),
120 ..Default::default()
121 };
122 Self { client, request }
123 }
124 pub fn with_include_shared_data(
126 mut self,
127 include_shared_data: impl Into<Option<bool>>,
128 ) -> Self {
129 self.request.include_shared_data = include_shared_data.into();
130 self
131 }
132}
133impl IntoFuture for GetShareBuilder {
134 type Output = Result<Share>;
135 type IntoFuture = BoxFut<'static, Self::Output>;
136 fn into_future(self) -> Self::IntoFuture {
137 let client = self.client;
138 let request = self.request;
139 Box::pin(async move { client.get_share(&request).await })
140 }
141}
142pub struct UpdateShareBuilder {
144 client: ShareServiceClient,
145 request: UpdateShareRequest,
146}
147impl UpdateShareBuilder {
148 pub(crate) fn new(client: ShareServiceClient, name: impl Into<String>) -> Self {
151 let request = UpdateShareRequest {
152 name: name.into(),
153 ..Default::default()
154 };
155 Self { client, request }
156 }
157 pub fn with_updates<I>(mut self, updates: I) -> Self
159 where
160 I: IntoIterator<Item = DataObjectUpdate>,
161 {
162 self.request.updates = updates.into_iter().collect();
163 self
164 }
165 pub fn with_new_name(mut self, new_name: impl Into<Option<String>>) -> Self {
167 self.request.new_name = new_name.into();
168 self
169 }
170 pub fn with_owner(mut self, owner: impl Into<Option<String>>) -> Self {
172 self.request.owner = owner.into();
173 self
174 }
175 pub fn with_comment(mut self, comment: impl Into<Option<String>>) -> Self {
177 self.request.comment = comment.into();
178 self
179 }
180}
181impl IntoFuture for UpdateShareBuilder {
182 type Output = Result<Share>;
183 type IntoFuture = BoxFut<'static, Self::Output>;
184 fn into_future(self) -> Self::IntoFuture {
185 let client = self.client;
186 let request = self.request;
187 Box::pin(async move { client.update_share(&request).await })
188 }
189}
190pub struct DeleteShareBuilder {
192 client: ShareServiceClient,
193 request: DeleteShareRequest,
194}
195impl DeleteShareBuilder {
196 pub(crate) fn new(client: ShareServiceClient, name: impl Into<String>) -> Self {
199 let request = DeleteShareRequest {
200 name: name.into(),
201 ..Default::default()
202 };
203 Self { client, request }
204 }
205}
206impl IntoFuture for DeleteShareBuilder {
207 type Output = Result<()>;
208 type IntoFuture = BoxFut<'static, Self::Output>;
209 fn into_future(self) -> Self::IntoFuture {
210 let client = self.client;
211 let request = self.request;
212 Box::pin(async move { client.delete_share(&request).await })
213 }
214}
215pub struct GetPermissionsBuilder {
217 client: ShareServiceClient,
218 request: GetPermissionsRequest,
219}
220impl GetPermissionsBuilder {
221 pub(crate) fn new(client: ShareServiceClient, name: impl Into<String>) -> Self {
224 let request = GetPermissionsRequest {
225 name: name.into(),
226 ..Default::default()
227 };
228 Self { client, request }
229 }
230 pub fn with_max_results(mut self, max_results: impl Into<Option<i32>>) -> Self {
232 self.request.max_results = max_results.into();
233 self
234 }
235 pub fn with_page_token(mut self, page_token: impl Into<Option<String>>) -> Self {
237 self.request.page_token = page_token.into();
238 self
239 }
240}
241impl IntoFuture for GetPermissionsBuilder {
242 type Output = Result<GetPermissionsResponse>;
243 type IntoFuture = BoxFut<'static, Self::Output>;
244 fn into_future(self) -> Self::IntoFuture {
245 let client = self.client;
246 let request = self.request;
247 Box::pin(async move { client.get_permissions(&request).await })
248 }
249}
250pub struct UpdatePermissionsBuilder {
252 client: ShareServiceClient,
253 request: UpdatePermissionsRequest,
254}
255impl UpdatePermissionsBuilder {
256 pub(crate) fn new(client: ShareServiceClient, name: impl Into<String>) -> Self {
259 let request = UpdatePermissionsRequest {
260 name: name.into(),
261 ..Default::default()
262 };
263 Self { client, request }
264 }
265 pub fn with_changes<I>(mut self, changes: I) -> Self
267 where
268 I: IntoIterator<Item = PermissionsChange>,
269 {
270 self.request.changes = changes.into_iter().collect();
271 self
272 }
273 pub fn with_omit_permissions_list(
275 mut self,
276 omit_permissions_list: impl Into<Option<bool>>,
277 ) -> Self {
278 self.request.omit_permissions_list = omit_permissions_list.into();
279 self
280 }
281}
282impl IntoFuture for UpdatePermissionsBuilder {
283 type Output = Result<UpdatePermissionsResponse>;
284 type IntoFuture = BoxFut<'static, Self::Output>;
285 fn into_future(self) -> Self::IntoFuture {
286 let client = self.client;
287 let request = self.request;
288 Box::pin(async move { client.update_permissions(&request).await })
289 }
290}