Skip to main content

unitycatalog_client/codegen/functions/
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::functions::v1::*;
18/// Builder for listing functions
19pub struct ListFunctionsBuilder {
20    client: FunctionServiceClient,
21    request: ListFunctionsRequest,
22}
23impl ListFunctionsBuilder {
24    /// Create a new builder instance.
25    /// Obtain via the corresponding method on `FunctionServiceClient`.
26    pub(crate) fn new(
27        client: FunctionServiceClient,
28        catalog_name: impl Into<String>,
29        schema_name: impl Into<String>,
30    ) -> Self {
31        let request = ListFunctionsRequest {
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 functions 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<Function>> {
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_functions(&builder.request).await?;
61                if let Some(ref mut rem) = remaining {
62                    *rem -= res.functions.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.functions.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 ListFunctionsBuilder {
82    type Output = Result<ListFunctionsResponse>;
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_functions(&request).await })
88    }
89}
90/// Builder for creating a function
91pub struct CreateFunctionBuilder {
92    client: FunctionServiceClient,
93    request: CreateFunctionRequest,
94}
95impl CreateFunctionBuilder {
96    /// Create a new builder instance.
97    /// Obtain via the corresponding method on `FunctionServiceClient`.
98    pub(crate) fn new(client: FunctionServiceClient, function_info: CreateFunction) -> Self {
99        let request = CreateFunctionRequest {
100            function_info: buffa::MessageField::some(function_info),
101            ..Default::default()
102        };
103        Self { client, request }
104    }
105}
106impl IntoFuture for CreateFunctionBuilder {
107    type Output = Result<Function>;
108    type IntoFuture = BoxFut<'static, Self::Output>;
109    fn into_future(self) -> Self::IntoFuture {
110        let client = self.client;
111        let request = self.request;
112        Box::pin(async move { client.create_function(&request).await })
113    }
114}
115/// Builder for getting a function
116pub struct GetFunctionBuilder {
117    client: FunctionServiceClient,
118    request: GetFunctionRequest,
119}
120impl GetFunctionBuilder {
121    /// Create a new builder instance.
122    /// Obtain via the corresponding method on `FunctionServiceClient`.
123    pub(crate) fn new(client: FunctionServiceClient, name: impl Into<String>) -> Self {
124        let request = GetFunctionRequest {
125            name: name.into(),
126            ..Default::default()
127        };
128        Self { client, request }
129    }
130}
131impl IntoFuture for GetFunctionBuilder {
132    type Output = Result<Function>;
133    type IntoFuture = BoxFut<'static, Self::Output>;
134    fn into_future(self) -> Self::IntoFuture {
135        let client = self.client;
136        let request = self.request;
137        Box::pin(async move { client.get_function(&request).await })
138    }
139}
140/// Builder for updating a function
141pub struct UpdateFunctionBuilder {
142    client: FunctionServiceClient,
143    request: UpdateFunctionRequest,
144}
145impl UpdateFunctionBuilder {
146    /// Create a new builder instance.
147    /// Obtain via the corresponding method on `FunctionServiceClient`.
148    pub(crate) fn new(client: FunctionServiceClient, name: impl Into<String>) -> Self {
149        let request = UpdateFunctionRequest {
150            name: name.into(),
151            ..Default::default()
152        };
153        Self { client, request }
154    }
155    /// Username of new owner of the function.
156    pub fn with_owner(mut self, owner: impl Into<Option<String>>) -> Self {
157        self.request.owner = owner.into();
158        self
159    }
160}
161impl IntoFuture for UpdateFunctionBuilder {
162    type Output = Result<Function>;
163    type IntoFuture = BoxFut<'static, Self::Output>;
164    fn into_future(self) -> Self::IntoFuture {
165        let client = self.client;
166        let request = self.request;
167        Box::pin(async move { client.update_function(&request).await })
168    }
169}
170/// Builder for deleting a function
171pub struct DeleteFunctionBuilder {
172    client: FunctionServiceClient,
173    request: DeleteFunctionRequest,
174}
175impl DeleteFunctionBuilder {
176    /// Create a new builder instance.
177    /// Obtain via the corresponding method on `FunctionServiceClient`.
178    pub(crate) fn new(client: FunctionServiceClient, name: impl Into<String>) -> Self {
179        let request = DeleteFunctionRequest {
180            name: name.into(),
181            ..Default::default()
182        };
183        Self { client, request }
184    }
185    /// Force deletion even if the function is not empty.
186    pub fn with_force(mut self, force: impl Into<Option<bool>>) -> Self {
187        self.request.force = force.into();
188        self
189    }
190}
191impl IntoFuture for DeleteFunctionBuilder {
192    type Output = Result<()>;
193    type IntoFuture = BoxFut<'static, Self::Output>;
194    fn into_future(self) -> Self::IntoFuture {
195        let client = self.client;
196        let request = self.request;
197        Box::pin(async move { client.delete_function(&request).await })
198    }
199}