unitycatalog_client/codegen/recipients/
builders.rs1#![allow(unused_mut)]
3#![allow(unused_imports)]
4type BoxFut<'a, T> = ::futures::future::BoxFuture<'a, T>;
5type BoxStr<'a, T> = ::futures::stream::BoxStream<'a, T>;
6use super::super::stream_paginated;
7use super::client::*;
8use crate::Result;
9use futures::{StreamExt, TryStreamExt};
10use std::future::IntoFuture;
11use unitycatalog_common::models::recipients::v1::*;
12pub struct ListRecipientsBuilder {
14 client: RecipientServiceClient,
15 request: ListRecipientsRequest,
16}
17impl ListRecipientsBuilder {
18 pub(crate) fn new(client: RecipientServiceClient) -> Self {
21 let request = ListRecipientsRequest {
22 ..Default::default()
23 };
24 Self { client, request }
25 }
26 pub fn with_max_results(mut self, max_results: impl Into<Option<i32>>) -> Self {
28 self.request.max_results = max_results.into();
29 self
30 }
31 pub fn with_page_token(mut self, page_token: impl Into<Option<String>>) -> Self {
33 self.request.page_token = page_token.into();
34 self
35 }
36 pub fn into_stream(self) -> BoxStr<'static, Result<Recipient>> {
38 let remaining = self.request.max_results;
39 let stream = stream_paginated(
40 (self, remaining),
41 move |(mut builder, mut remaining), page_token| async move {
42 builder.request.page_token = page_token;
43 let res = builder.client.list_recipients(&builder.request).await?;
44 if let Some(ref mut rem) = remaining {
45 *rem -= res.recipients.len() as i32;
46 }
47 let next_page_token = if remaining.is_some_and(|r| r <= 0) {
48 None
49 } else {
50 res.next_page_token.clone()
51 };
52 Ok((res, (builder, remaining), next_page_token))
53 },
54 )
55 .map_ok(|resp| futures::stream::iter(resp.recipients.into_iter().map(Ok)))
56 .try_flatten();
57 stream.boxed()
58 }
59}
60impl IntoFuture for ListRecipientsBuilder {
61 type Output = Result<ListRecipientsResponse>;
62 type IntoFuture = BoxFut<'static, Self::Output>;
63 fn into_future(self) -> Self::IntoFuture {
64 let client = self.client;
65 let request = self.request;
66 Box::pin(async move { client.list_recipients(&request).await })
67 }
68}
69pub struct CreateRecipientBuilder {
71 client: RecipientServiceClient,
72 request: CreateRecipientRequest,
73}
74impl CreateRecipientBuilder {
75 pub(crate) fn new(
78 client: RecipientServiceClient,
79 name: impl Into<String>,
80 authentication_type: AuthenticationType,
81 owner: impl Into<String>,
82 ) -> Self {
83 let request = CreateRecipientRequest {
84 name: name.into(),
85 authentication_type: buffa::EnumValue::Known(authentication_type),
86 owner: owner.into(),
87 ..Default::default()
88 };
89 Self { client, request }
90 }
91 pub fn with_comment(mut self, comment: impl Into<Option<String>>) -> Self {
93 self.request.comment = comment.into();
94 self
95 }
96 pub fn with_properties<I, K, V>(mut self, properties: I) -> Self
101 where
102 I: IntoIterator<Item = (K, V)>,
103 K: Into<String>,
104 V: Into<String>,
105 {
106 self.request.properties = properties
107 .into_iter()
108 .map(|(k, v)| (k.into(), v.into()))
109 .collect();
110 self
111 }
112 pub fn with_expiration_time(mut self, expiration_time: impl Into<Option<i64>>) -> Self {
114 self.request.expiration_time = expiration_time.into();
115 self
116 }
117}
118impl IntoFuture for CreateRecipientBuilder {
119 type Output = Result<Recipient>;
120 type IntoFuture = BoxFut<'static, Self::Output>;
121 fn into_future(self) -> Self::IntoFuture {
122 let client = self.client;
123 let request = self.request;
124 Box::pin(async move { client.create_recipient(&request).await })
125 }
126}
127pub struct GetRecipientBuilder {
129 client: RecipientServiceClient,
130 request: GetRecipientRequest,
131}
132impl GetRecipientBuilder {
133 pub(crate) fn new(client: RecipientServiceClient, name: impl Into<String>) -> Self {
136 let request = GetRecipientRequest {
137 name: name.into(),
138 ..Default::default()
139 };
140 Self { client, request }
141 }
142}
143impl IntoFuture for GetRecipientBuilder {
144 type Output = Result<Recipient>;
145 type IntoFuture = BoxFut<'static, Self::Output>;
146 fn into_future(self) -> Self::IntoFuture {
147 let client = self.client;
148 let request = self.request;
149 Box::pin(async move { client.get_recipient(&request).await })
150 }
151}
152pub struct UpdateRecipientBuilder {
154 client: RecipientServiceClient,
155 request: UpdateRecipientRequest,
156}
157impl UpdateRecipientBuilder {
158 pub(crate) fn new(client: RecipientServiceClient, name: impl Into<String>) -> Self {
161 let request = UpdateRecipientRequest {
162 name: name.into(),
163 ..Default::default()
164 };
165 Self { client, request }
166 }
167 pub fn with_new_name(mut self, new_name: impl Into<Option<String>>) -> Self {
169 self.request.new_name = new_name.into();
170 self
171 }
172 pub fn with_owner(mut self, owner: impl Into<Option<String>>) -> Self {
174 self.request.owner = owner.into();
175 self
176 }
177 pub fn with_comment(mut self, comment: impl Into<Option<String>>) -> Self {
179 self.request.comment = comment.into();
180 self
181 }
182 pub fn with_properties<I, K, V>(mut self, properties: I) -> Self
187 where
188 I: IntoIterator<Item = (K, V)>,
189 K: Into<String>,
190 V: Into<String>,
191 {
192 self.request.properties = properties
193 .into_iter()
194 .map(|(k, v)| (k.into(), v.into()))
195 .collect();
196 self
197 }
198 pub fn with_expiration_time(mut self, expiration_time: impl Into<Option<i64>>) -> Self {
200 self.request.expiration_time = expiration_time.into();
201 self
202 }
203}
204impl IntoFuture for UpdateRecipientBuilder {
205 type Output = Result<Recipient>;
206 type IntoFuture = BoxFut<'static, Self::Output>;
207 fn into_future(self) -> Self::IntoFuture {
208 let client = self.client;
209 let request = self.request;
210 Box::pin(async move { client.update_recipient(&request).await })
211 }
212}
213pub struct DeleteRecipientBuilder {
215 client: RecipientServiceClient,
216 request: DeleteRecipientRequest,
217}
218impl DeleteRecipientBuilder {
219 pub(crate) fn new(client: RecipientServiceClient, name: impl Into<String>) -> Self {
222 let request = DeleteRecipientRequest {
223 name: name.into(),
224 ..Default::default()
225 };
226 Self { client, request }
227 }
228}
229impl IntoFuture for DeleteRecipientBuilder {
230 type Output = Result<()>;
231 type IntoFuture = BoxFut<'static, Self::Output>;
232 fn into_future(self) -> Self::IntoFuture {
233 let client = self.client;
234 let request = self.request;
235 Box::pin(async move { client.delete_recipient(&request).await })
236 }
237}