unitycatalog_client/codegen/recipients/
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::recipients::v1::*;
18pub struct ListRecipientsBuilder {
20 client: RecipientServiceClient,
21 request: ListRecipientsRequest,
22}
23impl ListRecipientsBuilder {
24 pub(crate) fn new(client: RecipientServiceClient) -> Self {
27 let request = ListRecipientsRequest {
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<Recipient>> {
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_recipients(&builder.request).await?;
50 if let Some(ref mut rem) = remaining {
51 *rem -= res.recipients.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.recipients.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 ListRecipientsBuilder {
71 type Output = Result<ListRecipientsResponse>;
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_recipients(&request).await })
77 }
78}
79pub struct CreateRecipientBuilder {
81 client: RecipientServiceClient,
82 request: CreateRecipientRequest,
83}
84impl CreateRecipientBuilder {
85 pub(crate) fn new(
88 client: RecipientServiceClient,
89 name: impl Into<String>,
90 authentication_type: AuthenticationType,
91 owner: impl Into<String>,
92 ) -> Self {
93 let request = CreateRecipientRequest {
94 name: name.into(),
95 authentication_type: buffa::EnumValue::Known(authentication_type),
96 owner: owner.into(),
97 ..Default::default()
98 };
99 Self { client, request }
100 }
101 pub fn with_comment(mut self, comment: impl Into<Option<String>>) -> Self {
103 self.request.comment = comment.into();
104 self
105 }
106 pub fn with_properties<I, K, V>(mut self, properties: I) -> Self
111 where
112 I: IntoIterator<Item = (K, V)>,
113 K: Into<String>,
114 V: Into<String>,
115 {
116 self.request.properties = properties
117 .into_iter()
118 .map(|(k, v)| (k.into(), v.into()))
119 .collect();
120 self
121 }
122 pub fn with_expiration_time(mut self, expiration_time: impl Into<Option<i64>>) -> Self {
124 self.request.expiration_time = expiration_time.into();
125 self
126 }
127}
128impl IntoFuture for CreateRecipientBuilder {
129 type Output = Result<Recipient>;
130 type IntoFuture = BoxFut<'static, Self::Output>;
131 fn into_future(self) -> Self::IntoFuture {
132 let client = self.client;
133 let request = self.request;
134 Box::pin(async move { client.create_recipient(&request).await })
135 }
136}
137pub struct GetRecipientBuilder {
139 client: RecipientServiceClient,
140 request: GetRecipientRequest,
141}
142impl GetRecipientBuilder {
143 pub(crate) fn new(client: RecipientServiceClient, name: impl Into<String>) -> Self {
146 let request = GetRecipientRequest {
147 name: name.into(),
148 ..Default::default()
149 };
150 Self { client, request }
151 }
152}
153impl IntoFuture for GetRecipientBuilder {
154 type Output = Result<Recipient>;
155 type IntoFuture = BoxFut<'static, Self::Output>;
156 fn into_future(self) -> Self::IntoFuture {
157 let client = self.client;
158 let request = self.request;
159 Box::pin(async move { client.get_recipient(&request).await })
160 }
161}
162pub struct UpdateRecipientBuilder {
164 client: RecipientServiceClient,
165 request: UpdateRecipientRequest,
166}
167impl UpdateRecipientBuilder {
168 pub(crate) fn new(client: RecipientServiceClient, name: impl Into<String>) -> Self {
171 let request = UpdateRecipientRequest {
172 name: name.into(),
173 ..Default::default()
174 };
175 Self { client, request }
176 }
177 pub fn with_new_name(mut self, new_name: impl Into<Option<String>>) -> Self {
179 self.request.new_name = new_name.into();
180 self
181 }
182 pub fn with_owner(mut self, owner: impl Into<Option<String>>) -> Self {
184 self.request.owner = owner.into();
185 self
186 }
187 pub fn with_comment(mut self, comment: impl Into<Option<String>>) -> Self {
189 self.request.comment = comment.into();
190 self
191 }
192 pub fn with_properties<I, K, V>(mut self, properties: I) -> Self
197 where
198 I: IntoIterator<Item = (K, V)>,
199 K: Into<String>,
200 V: Into<String>,
201 {
202 self.request.properties = properties
203 .into_iter()
204 .map(|(k, v)| (k.into(), v.into()))
205 .collect();
206 self
207 }
208 pub fn with_expiration_time(mut self, expiration_time: impl Into<Option<i64>>) -> Self {
210 self.request.expiration_time = expiration_time.into();
211 self
212 }
213}
214impl IntoFuture for UpdateRecipientBuilder {
215 type Output = Result<Recipient>;
216 type IntoFuture = BoxFut<'static, Self::Output>;
217 fn into_future(self) -> Self::IntoFuture {
218 let client = self.client;
219 let request = self.request;
220 Box::pin(async move { client.update_recipient(&request).await })
221 }
222}
223pub struct DeleteRecipientBuilder {
225 client: RecipientServiceClient,
226 request: DeleteRecipientRequest,
227}
228impl DeleteRecipientBuilder {
229 pub(crate) fn new(client: RecipientServiceClient, name: impl Into<String>) -> Self {
232 let request = DeleteRecipientRequest {
233 name: name.into(),
234 ..Default::default()
235 };
236 Self { client, request }
237 }
238}
239impl IntoFuture for DeleteRecipientBuilder {
240 type Output = Result<()>;
241 type IntoFuture = BoxFut<'static, Self::Output>;
242 fn into_future(self) -> Self::IntoFuture {
243 let client = self.client;
244 let request = self.request;
245 Box::pin(async move { client.delete_recipient(&request).await })
246 }
247}