Skip to main content

unitycatalog_client/codegen/volumes/
builders.rs

1// @generated — do not edit by hand.
2#![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::volumes::v1::*;
18/// Builder for listing volumes
19pub struct ListVolumesBuilder {
20    client: VolumeServiceClient,
21    request: ListVolumesRequest,
22}
23impl ListVolumesBuilder {
24    /// Create a new builder instance.
25    /// Obtain via the corresponding method on `VolumeServiceClient`.
26    pub(crate) fn new(
27        client: VolumeServiceClient,
28        catalog_name: impl Into<String>,
29        schema_name: impl Into<String>,
30    ) -> Self {
31        let request = ListVolumesRequest {
32            catalog_name: catalog_name.into(),
33            schema_name: schema_name.into(),
34            ..Default::default()
35        };
36        Self { client, request }
37    }
38    /// The maximum number of results per page that should be returned.
39    pub fn with_max_results(mut self, max_results: impl Into<Option<i32>>) -> Self {
40        self.request.max_results = max_results.into();
41        self
42    }
43    /// Opaque pagination token to go to next page based on previous query.
44    pub fn with_page_token(mut self, page_token: impl Into<Option<String>>) -> Self {
45        self.request.page_token = page_token.into();
46        self
47    }
48    /// Whether to include schemas in the response for which the principal can only access selective metadata for
49    pub fn with_include_browse(mut self, include_browse: impl Into<Option<bool>>) -> Self {
50        self.request.include_browse = include_browse.into();
51        self
52    }
53    /// Convert paginated request into stream of results
54    pub fn into_stream(self) -> BoxStr<'static, Result<Volume>> {
55        let remaining = self.request.max_results;
56        let stream = stream_paginated(
57            (self, remaining),
58            move |(mut builder, mut remaining), page_token| async move {
59                builder.request.page_token = page_token;
60                let res = builder.client.list_volumes(&builder.request).await?;
61                if let Some(ref mut rem) = remaining {
62                    *rem -= res.volumes.len() as i32;
63                }
64                let next_page_token = if remaining.is_some_and(|r| r <= 0) {
65                    None
66                } else {
67                    res.next_page_token.clone()
68                };
69                Ok((res, (builder, remaining), next_page_token))
70            },
71        )
72        .map_ok(|resp| futures::stream::iter(resp.volumes.into_iter().map(Ok)))
73        .try_flatten();
74        #[cfg(not(target_arch = "wasm32"))]
75        let stream = stream.boxed();
76        #[cfg(target_arch = "wasm32")]
77        let stream = stream.boxed_local();
78        stream
79    }
80}
81impl IntoFuture for ListVolumesBuilder {
82    type Output = Result<ListVolumesResponse>;
83    type IntoFuture = BoxFut<'static, Self::Output>;
84    fn into_future(self) -> Self::IntoFuture {
85        let client = self.client;
86        let request = self.request;
87        Box::pin(async move { client.list_volumes(&request).await })
88    }
89}
90/// Builder for creating a volume
91pub struct CreateVolumeBuilder {
92    client: VolumeServiceClient,
93    request: CreateVolumeRequest,
94}
95impl CreateVolumeBuilder {
96    /// Create a new builder instance.
97    /// Obtain via the corresponding method on `VolumeServiceClient`.
98    pub(crate) fn new(
99        client: VolumeServiceClient,
100        catalog_name: impl Into<String>,
101        schema_name: impl Into<String>,
102        name: impl Into<String>,
103        volume_type: VolumeType,
104    ) -> Self {
105        let request = CreateVolumeRequest {
106            catalog_name: catalog_name.into(),
107            schema_name: schema_name.into(),
108            name: name.into(),
109            volume_type: buffa::EnumValue::Known(volume_type),
110            ..Default::default()
111        };
112        Self { client, request }
113    }
114    /// The storage location on the cloud
115    pub fn with_storage_location(mut self, storage_location: impl Into<Option<String>>) -> Self {
116        self.request.storage_location = storage_location.into();
117        self
118    }
119    /// The storage location on the cloud
120    pub fn with_comment(mut self, comment: impl Into<Option<String>>) -> Self {
121        self.request.comment = comment.into();
122        self
123    }
124}
125impl IntoFuture for CreateVolumeBuilder {
126    type Output = Result<Volume>;
127    type IntoFuture = BoxFut<'static, Self::Output>;
128    fn into_future(self) -> Self::IntoFuture {
129        let client = self.client;
130        let request = self.request;
131        Box::pin(async move { client.create_volume(&request).await })
132    }
133}
134/// Builder for getting a volume
135pub struct GetVolumeBuilder {
136    client: VolumeServiceClient,
137    request: GetVolumeRequest,
138}
139impl GetVolumeBuilder {
140    /// Create a new builder instance.
141    /// Obtain via the corresponding method on `VolumeServiceClient`.
142    pub(crate) fn new(client: VolumeServiceClient, name: impl Into<String>) -> Self {
143        let request = GetVolumeRequest {
144            name: name.into(),
145            ..Default::default()
146        };
147        Self { client, request }
148    }
149    /// Whether to include schemas in the response for which the principal can only access selective metadata for
150    pub fn with_include_browse(mut self, include_browse: impl Into<Option<bool>>) -> Self {
151        self.request.include_browse = include_browse.into();
152        self
153    }
154}
155impl IntoFuture for GetVolumeBuilder {
156    type Output = Result<Volume>;
157    type IntoFuture = BoxFut<'static, Self::Output>;
158    fn into_future(self) -> Self::IntoFuture {
159        let client = self.client;
160        let request = self.request;
161        Box::pin(async move { client.get_volume(&request).await })
162    }
163}
164/// Builder for updating a volume
165pub struct UpdateVolumeBuilder {
166    client: VolumeServiceClient,
167    request: UpdateVolumeRequest,
168}
169impl UpdateVolumeBuilder {
170    /// Create a new builder instance.
171    /// Obtain via the corresponding method on `VolumeServiceClient`.
172    pub(crate) fn new(client: VolumeServiceClient, name: impl Into<String>) -> Self {
173        let request = UpdateVolumeRequest {
174            name: name.into(),
175            ..Default::default()
176        };
177        Self { client, request }
178    }
179    /// New name for the volume.
180    pub fn with_new_name(mut self, new_name: impl Into<Option<String>>) -> Self {
181        self.request.new_name = new_name.into();
182        self
183    }
184    /// The comment attached to the volume
185    pub fn with_comment(mut self, comment: impl Into<Option<String>>) -> Self {
186        self.request.comment = comment.into();
187        self
188    }
189    /// The identifier of the user who owns the volume
190    pub fn with_owner(mut self, owner: impl Into<Option<String>>) -> Self {
191        self.request.owner = owner.into();
192        self
193    }
194}
195impl IntoFuture for UpdateVolumeBuilder {
196    type Output = Result<Volume>;
197    type IntoFuture = BoxFut<'static, Self::Output>;
198    fn into_future(self) -> Self::IntoFuture {
199        let client = self.client;
200        let request = self.request;
201        Box::pin(async move { client.update_volume(&request).await })
202    }
203}
204/// Builder for deleting a volume
205pub struct DeleteVolumeBuilder {
206    client: VolumeServiceClient,
207    request: DeleteVolumeRequest,
208}
209impl DeleteVolumeBuilder {
210    /// Create a new builder instance.
211    /// Obtain via the corresponding method on `VolumeServiceClient`.
212    pub(crate) fn new(client: VolumeServiceClient, name: impl Into<String>) -> Self {
213        let request = DeleteVolumeRequest {
214            name: name.into(),
215            ..Default::default()
216        };
217        Self { client, request }
218    }
219}
220impl IntoFuture for DeleteVolumeBuilder {
221    type Output = Result<()>;
222    type IntoFuture = BoxFut<'static, Self::Output>;
223    fn into_future(self) -> Self::IntoFuture {
224        let client = self.client;
225        let request = self.request;
226        Box::pin(async move { client.delete_volume(&request).await })
227    }
228}