unitycatalog_client/codegen/volumes/
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::volumes::v1::*;
12pub struct ListVolumesBuilder {
14 client: VolumeServiceClient,
15 request: ListVolumesRequest,
16}
17impl ListVolumesBuilder {
18 pub(crate) fn new(
21 client: VolumeServiceClient,
22 catalog_name: impl Into<String>,
23 schema_name: impl Into<String>,
24 ) -> Self {
25 let request = ListVolumesRequest {
26 catalog_name: catalog_name.into(),
27 schema_name: schema_name.into(),
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 with_include_browse(mut self, include_browse: impl Into<Option<bool>>) -> Self {
44 self.request.include_browse = include_browse.into();
45 self
46 }
47 pub fn into_stream(self) -> BoxStr<'static, Result<Volume>> {
49 let remaining = self.request.max_results;
50 let stream = stream_paginated(
51 (self, remaining),
52 move |(mut builder, mut remaining), page_token| async move {
53 builder.request.page_token = page_token;
54 let res = builder.client.list_volumes(&builder.request).await?;
55 if let Some(ref mut rem) = remaining {
56 *rem -= res.volumes.len() as i32;
57 }
58 let next_page_token = if remaining.is_some_and(|r| r <= 0) {
59 None
60 } else {
61 res.next_page_token.clone()
62 };
63 Ok((res, (builder, remaining), next_page_token))
64 },
65 )
66 .map_ok(|resp| futures::stream::iter(resp.volumes.into_iter().map(Ok)))
67 .try_flatten();
68 stream.boxed()
69 }
70}
71impl IntoFuture for ListVolumesBuilder {
72 type Output = Result<ListVolumesResponse>;
73 type IntoFuture = BoxFut<'static, Self::Output>;
74 fn into_future(self) -> Self::IntoFuture {
75 let client = self.client;
76 let request = self.request;
77 Box::pin(async move { client.list_volumes(&request).await })
78 }
79}
80pub struct CreateVolumeBuilder {
82 client: VolumeServiceClient,
83 request: CreateVolumeRequest,
84}
85impl CreateVolumeBuilder {
86 pub(crate) fn new(
89 client: VolumeServiceClient,
90 catalog_name: impl Into<String>,
91 schema_name: impl Into<String>,
92 name: impl Into<String>,
93 volume_type: VolumeType,
94 ) -> Self {
95 let request = CreateVolumeRequest {
96 catalog_name: catalog_name.into(),
97 schema_name: schema_name.into(),
98 name: name.into(),
99 volume_type: volume_type as i32,
100 ..Default::default()
101 };
102 Self { client, request }
103 }
104 pub fn with_storage_location(mut self, storage_location: impl Into<Option<String>>) -> Self {
106 self.request.storage_location = storage_location.into();
107 self
108 }
109 pub fn with_comment(mut self, comment: impl Into<Option<String>>) -> Self {
111 self.request.comment = comment.into();
112 self
113 }
114}
115impl IntoFuture for CreateVolumeBuilder {
116 type Output = Result<Volume>;
117 type IntoFuture = BoxFut<'static, Self::Output>;
118 fn into_future(self) -> Self::IntoFuture {
119 let client = self.client;
120 let request = self.request;
121 Box::pin(async move { client.create_volume(&request).await })
122 }
123}
124pub struct GetVolumeBuilder {
126 client: VolumeServiceClient,
127 request: GetVolumeRequest,
128}
129impl GetVolumeBuilder {
130 pub(crate) fn new(client: VolumeServiceClient, name: impl Into<String>) -> Self {
133 let request = GetVolumeRequest {
134 name: name.into(),
135 ..Default::default()
136 };
137 Self { client, request }
138 }
139 pub fn with_include_browse(mut self, include_browse: impl Into<Option<bool>>) -> Self {
141 self.request.include_browse = include_browse.into();
142 self
143 }
144}
145impl IntoFuture for GetVolumeBuilder {
146 type Output = Result<Volume>;
147 type IntoFuture = BoxFut<'static, Self::Output>;
148 fn into_future(self) -> Self::IntoFuture {
149 let client = self.client;
150 let request = self.request;
151 Box::pin(async move { client.get_volume(&request).await })
152 }
153}
154pub struct UpdateVolumeBuilder {
156 client: VolumeServiceClient,
157 request: UpdateVolumeRequest,
158}
159impl UpdateVolumeBuilder {
160 pub(crate) fn new(client: VolumeServiceClient, name: impl Into<String>) -> Self {
163 let request = UpdateVolumeRequest {
164 name: name.into(),
165 ..Default::default()
166 };
167 Self { client, request }
168 }
169 pub fn with_new_name(mut self, new_name: impl Into<Option<String>>) -> Self {
171 self.request.new_name = new_name.into();
172 self
173 }
174 pub fn with_comment(mut self, comment: impl Into<Option<String>>) -> Self {
176 self.request.comment = comment.into();
177 self
178 }
179 pub fn with_owner(mut self, owner: impl Into<Option<String>>) -> Self {
181 self.request.owner = owner.into();
182 self
183 }
184}
185impl IntoFuture for UpdateVolumeBuilder {
186 type Output = Result<Volume>;
187 type IntoFuture = BoxFut<'static, Self::Output>;
188 fn into_future(self) -> Self::IntoFuture {
189 let client = self.client;
190 let request = self.request;
191 Box::pin(async move { client.update_volume(&request).await })
192 }
193}
194pub struct DeleteVolumeBuilder {
196 client: VolumeServiceClient,
197 request: DeleteVolumeRequest,
198}
199impl DeleteVolumeBuilder {
200 pub(crate) fn new(client: VolumeServiceClient, name: impl Into<String>) -> Self {
203 let request = DeleteVolumeRequest { name: name.into() };
204 Self { client, request }
205 }
206}
207impl IntoFuture for DeleteVolumeBuilder {
208 type Output = Result<()>;
209 type IntoFuture = BoxFut<'static, Self::Output>;
210 fn into_future(self) -> Self::IntoFuture {
211 let client = self.client;
212 let request = self.request;
213 Box::pin(async move { client.delete_volume(&request).await })
214 }
215}