unitycatalog_client/codegen/catalogs/
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::catalogs::v1::*;
12pub struct ListCatalogsBuilder {
14 client: CatalogServiceClient,
15 request: ListCatalogsRequest,
16}
17impl ListCatalogsBuilder {
18 pub(crate) fn new(client: CatalogServiceClient) -> Self {
21 let request = ListCatalogsRequest {
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<Catalog>> {
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_catalogs(&builder.request).await?;
44 if let Some(ref mut rem) = remaining {
45 *rem -= res.catalogs.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.catalogs.into_iter().map(Ok)))
56 .try_flatten();
57 stream.boxed()
58 }
59}
60impl IntoFuture for ListCatalogsBuilder {
61 type Output = Result<ListCatalogsResponse>;
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_catalogs(&request).await })
67 }
68}
69pub struct CreateCatalogBuilder {
71 client: CatalogServiceClient,
72 request: CreateCatalogRequest,
73}
74impl CreateCatalogBuilder {
75 pub(crate) fn new(client: CatalogServiceClient, name: impl Into<String>) -> Self {
78 let request = CreateCatalogRequest {
79 name: name.into(),
80 ..Default::default()
81 };
82 Self { client, request }
83 }
84 pub fn with_comment(mut self, comment: impl Into<Option<String>>) -> Self {
86 self.request.comment = comment.into();
87 self
88 }
89 pub fn with_properties<I, K, V>(mut self, properties: I) -> Self
91 where
92 I: IntoIterator<Item = (K, V)>,
93 K: Into<String>,
94 V: Into<String>,
95 {
96 self.request.properties = properties
97 .into_iter()
98 .map(|(k, v)| (k.into(), v.into()))
99 .collect();
100 self
101 }
102 pub fn with_storage_root(mut self, storage_root: impl Into<Option<String>>) -> Self {
104 self.request.storage_root = storage_root.into();
105 self
106 }
107 pub fn with_provider_name(mut self, provider_name: impl Into<Option<String>>) -> Self {
111 self.request.provider_name = provider_name.into();
112 self
113 }
114 pub fn with_share_name(mut self, share_name: impl Into<Option<String>>) -> Self {
116 self.request.share_name = share_name.into();
117 self
118 }
119}
120impl IntoFuture for CreateCatalogBuilder {
121 type Output = Result<Catalog>;
122 type IntoFuture = BoxFut<'static, Self::Output>;
123 fn into_future(self) -> Self::IntoFuture {
124 let client = self.client;
125 let request = self.request;
126 Box::pin(async move { client.create_catalog(&request).await })
127 }
128}
129pub struct GetCatalogBuilder {
131 client: CatalogServiceClient,
132 request: GetCatalogRequest,
133}
134impl GetCatalogBuilder {
135 pub(crate) fn new(client: CatalogServiceClient, name: impl Into<String>) -> Self {
138 let request = GetCatalogRequest {
139 name: name.into(),
140 ..Default::default()
141 };
142 Self { client, request }
143 }
144 pub fn with_include_browse(mut self, include_browse: impl Into<Option<bool>>) -> Self {
146 self.request.include_browse = include_browse.into();
147 self
148 }
149}
150impl IntoFuture for GetCatalogBuilder {
151 type Output = Result<Catalog>;
152 type IntoFuture = BoxFut<'static, Self::Output>;
153 fn into_future(self) -> Self::IntoFuture {
154 let client = self.client;
155 let request = self.request;
156 Box::pin(async move { client.get_catalog(&request).await })
157 }
158}
159pub struct UpdateCatalogBuilder {
161 client: CatalogServiceClient,
162 request: UpdateCatalogRequest,
163}
164impl UpdateCatalogBuilder {
165 pub(crate) fn new(client: CatalogServiceClient, name: impl Into<String>) -> Self {
168 let request = UpdateCatalogRequest {
169 name: name.into(),
170 ..Default::default()
171 };
172 Self { client, request }
173 }
174 pub fn with_owner(mut self, owner: impl Into<Option<String>>) -> Self {
176 self.request.owner = owner.into();
177 self
178 }
179 pub fn with_comment(mut self, comment: impl Into<Option<String>>) -> Self {
181 self.request.comment = comment.into();
182 self
183 }
184 pub fn with_properties<I, K, V>(mut self, properties: I) -> Self
189 where
190 I: IntoIterator<Item = (K, V)>,
191 K: Into<String>,
192 V: Into<String>,
193 {
194 self.request.properties = properties
195 .into_iter()
196 .map(|(k, v)| (k.into(), v.into()))
197 .collect();
198 self
199 }
200 pub fn with_new_name(mut self, new_name: impl Into<Option<String>>) -> Self {
202 self.request.new_name = new_name.into();
203 self
204 }
205}
206impl IntoFuture for UpdateCatalogBuilder {
207 type Output = Result<Catalog>;
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.update_catalog(&request).await })
213 }
214}
215pub struct DeleteCatalogBuilder {
217 client: CatalogServiceClient,
218 request: DeleteCatalogRequest,
219}
220impl DeleteCatalogBuilder {
221 pub(crate) fn new(client: CatalogServiceClient, name: impl Into<String>) -> Self {
224 let request = DeleteCatalogRequest {
225 name: name.into(),
226 ..Default::default()
227 };
228 Self { client, request }
229 }
230 pub fn with_force(mut self, force: impl Into<Option<bool>>) -> Self {
232 self.request.force = force.into();
233 self
234 }
235}
236impl IntoFuture for DeleteCatalogBuilder {
237 type Output = Result<()>;
238 type IntoFuture = BoxFut<'static, Self::Output>;
239 fn into_future(self) -> Self::IntoFuture {
240 let client = self.client;
241 let request = self.request;
242 Box::pin(async move { client.delete_catalog(&request).await })
243 }
244}