unitycatalog_client/codegen/catalogs/
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::catalogs::v1::*;
18pub struct ListCatalogsBuilder {
20 client: CatalogServiceClient,
21 request: ListCatalogsRequest,
22}
23impl ListCatalogsBuilder {
24 pub(crate) fn new(client: CatalogServiceClient) -> Self {
27 let request = ListCatalogsRequest {
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<Catalog>> {
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_catalogs(&builder.request).await?;
50 if let Some(ref mut rem) = remaining {
51 *rem -= res.catalogs.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.catalogs.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 ListCatalogsBuilder {
71 type Output = Result<ListCatalogsResponse>;
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_catalogs(&request).await })
77 }
78}
79pub struct CreateCatalogBuilder {
81 client: CatalogServiceClient,
82 request: CreateCatalogRequest,
83}
84impl CreateCatalogBuilder {
85 pub(crate) fn new(client: CatalogServiceClient, name: impl Into<String>) -> Self {
88 let request = CreateCatalogRequest {
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 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_storage_root(mut self, storage_root: impl Into<Option<String>>) -> Self {
114 self.request.storage_root = storage_root.into();
115 self
116 }
117 pub fn with_provider_name(mut self, provider_name: impl Into<Option<String>>) -> Self {
121 self.request.provider_name = provider_name.into();
122 self
123 }
124 pub fn with_share_name(mut self, share_name: impl Into<Option<String>>) -> Self {
126 self.request.share_name = share_name.into();
127 self
128 }
129}
130impl IntoFuture for CreateCatalogBuilder {
131 type Output = Result<Catalog>;
132 type IntoFuture = BoxFut<'static, Self::Output>;
133 fn into_future(self) -> Self::IntoFuture {
134 let client = self.client;
135 let request = self.request;
136 Box::pin(async move { client.create_catalog(&request).await })
137 }
138}
139pub struct GetCatalogBuilder {
141 client: CatalogServiceClient,
142 request: GetCatalogRequest,
143}
144impl GetCatalogBuilder {
145 pub(crate) fn new(client: CatalogServiceClient, name: impl Into<String>) -> Self {
148 let request = GetCatalogRequest {
149 name: name.into(),
150 ..Default::default()
151 };
152 Self { client, request }
153 }
154 pub fn with_include_browse(mut self, include_browse: impl Into<Option<bool>>) -> Self {
156 self.request.include_browse = include_browse.into();
157 self
158 }
159}
160impl IntoFuture for GetCatalogBuilder {
161 type Output = Result<Catalog>;
162 type IntoFuture = BoxFut<'static, Self::Output>;
163 fn into_future(self) -> Self::IntoFuture {
164 let client = self.client;
165 let request = self.request;
166 Box::pin(async move { client.get_catalog(&request).await })
167 }
168}
169pub struct UpdateCatalogBuilder {
171 client: CatalogServiceClient,
172 request: UpdateCatalogRequest,
173}
174impl UpdateCatalogBuilder {
175 pub(crate) fn new(client: CatalogServiceClient, name: impl Into<String>) -> Self {
178 let request = UpdateCatalogRequest {
179 name: name.into(),
180 ..Default::default()
181 };
182 Self { client, request }
183 }
184 pub fn with_owner(mut self, owner: impl Into<Option<String>>) -> Self {
186 self.request.owner = owner.into();
187 self
188 }
189 pub fn with_comment(mut self, comment: impl Into<Option<String>>) -> Self {
191 self.request.comment = comment.into();
192 self
193 }
194 pub fn with_properties<I, K, V>(mut self, properties: I) -> Self
199 where
200 I: IntoIterator<Item = (K, V)>,
201 K: Into<String>,
202 V: Into<String>,
203 {
204 self.request.properties = properties
205 .into_iter()
206 .map(|(k, v)| (k.into(), v.into()))
207 .collect();
208 self
209 }
210 pub fn with_new_name(mut self, new_name: impl Into<Option<String>>) -> Self {
212 self.request.new_name = new_name.into();
213 self
214 }
215}
216impl IntoFuture for UpdateCatalogBuilder {
217 type Output = Result<Catalog>;
218 type IntoFuture = BoxFut<'static, Self::Output>;
219 fn into_future(self) -> Self::IntoFuture {
220 let client = self.client;
221 let request = self.request;
222 Box::pin(async move { client.update_catalog(&request).await })
223 }
224}
225pub struct DeleteCatalogBuilder {
227 client: CatalogServiceClient,
228 request: DeleteCatalogRequest,
229}
230impl DeleteCatalogBuilder {
231 pub(crate) fn new(client: CatalogServiceClient, name: impl Into<String>) -> Self {
234 let request = DeleteCatalogRequest {
235 name: name.into(),
236 ..Default::default()
237 };
238 Self { client, request }
239 }
240 pub fn with_force(mut self, force: impl Into<Option<bool>>) -> Self {
242 self.request.force = force.into();
243 self
244 }
245}
246impl IntoFuture for DeleteCatalogBuilder {
247 type Output = Result<()>;
248 type IntoFuture = BoxFut<'static, Self::Output>;
249 fn into_future(self) -> Self::IntoFuture {
250 let client = self.client;
251 let request = self.request;
252 Box::pin(async move { client.delete_catalog(&request).await })
253 }
254}