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)]
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::*;
12/// Builder for listing volumes
13pub struct ListVolumesBuilder {
14    client: VolumeServiceClient,
15    request: ListVolumesRequest,
16}
17impl ListVolumesBuilder {
18    /// Create a new builder instance.
19    /// Obtain via the corresponding method on `VolumeServiceClient`.
20    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    /// The maximum number of results per page that should be returned.
33    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    /// Opaque pagination token to go to next page based on previous query.
38    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    /// Whether to include schemas in the response for which the principal can only access selective metadata for
43    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    /// Convert paginated request into stream of results
48    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}
80/// Builder for creating a volume
81pub struct CreateVolumeBuilder {
82    client: VolumeServiceClient,
83    request: CreateVolumeRequest,
84}
85impl CreateVolumeBuilder {
86    /// Create a new builder instance.
87    /// Obtain via the corresponding method on `VolumeServiceClient`.
88    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: buffa::EnumValue::Known(volume_type),
100            ..Default::default()
101        };
102        Self { client, request }
103    }
104    /// The storage location on the cloud
105    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    /// The storage location on the cloud
110    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}
124/// Builder for getting a volume
125pub struct GetVolumeBuilder {
126    client: VolumeServiceClient,
127    request: GetVolumeRequest,
128}
129impl GetVolumeBuilder {
130    /// Create a new builder instance.
131    /// Obtain via the corresponding method on `VolumeServiceClient`.
132    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    /// Whether to include schemas in the response for which the principal can only access selective metadata for
140    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}
154/// Builder for updating a volume
155pub struct UpdateVolumeBuilder {
156    client: VolumeServiceClient,
157    request: UpdateVolumeRequest,
158}
159impl UpdateVolumeBuilder {
160    /// Create a new builder instance.
161    /// Obtain via the corresponding method on `VolumeServiceClient`.
162    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    /// New name for the volume.
170    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    /// The comment attached to the volume
175    pub fn with_comment(mut self, comment: impl Into<Option<String>>) -> Self {
176        self.request.comment = comment.into();
177        self
178    }
179    /// The identifier of the user who owns the volume
180    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}
194/// Builder for deleting a volume
195pub struct DeleteVolumeBuilder {
196    client: VolumeServiceClient,
197    request: DeleteVolumeRequest,
198}
199impl DeleteVolumeBuilder {
200    /// Create a new builder instance.
201    /// Obtain via the corresponding method on `VolumeServiceClient`.
202    pub(crate) fn new(client: VolumeServiceClient, name: impl Into<String>) -> Self {
203        let request = DeleteVolumeRequest {
204            name: name.into(),
205            ..Default::default()
206        };
207        Self { client, request }
208    }
209}
210impl IntoFuture for DeleteVolumeBuilder {
211    type Output = Result<()>;
212    type IntoFuture = BoxFut<'static, Self::Output>;
213    fn into_future(self) -> Self::IntoFuture {
214        let client = self.client;
215        let request = self.request;
216        Box::pin(async move { client.delete_volume(&request).await })
217    }
218}