google_cloud_api_servicecontrol_v2/
builder.rs

1// Copyright 2025 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14//
15// Code generated by sidekick. DO NOT EDIT.
16
17pub mod service_controller {
18    use crate::Result;
19
20    /// A builder for [ServiceController][crate::client::ServiceController].
21    ///
22    /// ```
23    /// # async fn sample() -> gax::client_builder::Result<()> {
24    /// # use google_cloud_api_servicecontrol_v2::*;
25    /// # use builder::service_controller::ClientBuilder;
26    /// # use client::ServiceController;
27    /// let builder : ClientBuilder = ServiceController::builder();
28    /// let client = builder
29    ///     .with_endpoint("https://servicecontrol.googleapis.com")
30    ///     .build().await?;
31    /// # Ok(()) }
32    /// ```
33    pub type ClientBuilder =
34        gax::client_builder::ClientBuilder<client::Factory, gaxi::options::Credentials>;
35
36    pub(crate) mod client {
37        use super::super::super::client::ServiceController;
38        pub struct Factory;
39        impl gax::client_builder::internal::ClientFactory for Factory {
40            type Client = ServiceController;
41            type Credentials = gaxi::options::Credentials;
42            async fn build(
43                self,
44                config: gaxi::options::ClientConfig,
45            ) -> gax::client_builder::Result<Self::Client> {
46                Self::Client::new(config).await
47            }
48        }
49    }
50
51    /// Common implementation for [crate::client::ServiceController] request builders.
52    #[derive(Clone, Debug)]
53    pub(crate) struct RequestBuilder<R: std::default::Default> {
54        stub: std::sync::Arc<dyn super::super::stub::dynamic::ServiceController>,
55        request: R,
56        options: gax::options::RequestOptions,
57    }
58
59    impl<R> RequestBuilder<R>
60    where
61        R: std::default::Default,
62    {
63        pub(crate) fn new(
64            stub: std::sync::Arc<dyn super::super::stub::dynamic::ServiceController>,
65        ) -> Self {
66            Self {
67                stub,
68                request: R::default(),
69                options: gax::options::RequestOptions::default(),
70            }
71        }
72    }
73
74    /// The request builder for [ServiceController::check][crate::client::ServiceController::check] calls.
75    ///
76    /// # Example
77    /// ```
78    /// # use google_cloud_api_servicecontrol_v2::builder::service_controller::Check;
79    /// # async fn sample() -> gax::Result<()> {
80    ///
81    /// let builder = prepare_request_builder();
82    /// let response = builder.send().await?;
83    /// # Ok(()) }
84    ///
85    /// fn prepare_request_builder() -> Check {
86    ///   # panic!();
87    ///   // ... details omitted ...
88    /// }
89    /// ```
90    #[derive(Clone, Debug)]
91    pub struct Check(RequestBuilder<crate::model::CheckRequest>);
92
93    impl Check {
94        pub(crate) fn new(
95            stub: std::sync::Arc<dyn super::super::stub::dynamic::ServiceController>,
96        ) -> Self {
97            Self(RequestBuilder::new(stub))
98        }
99
100        /// Sets the full request, replacing any prior values.
101        pub fn with_request<V: Into<crate::model::CheckRequest>>(mut self, v: V) -> Self {
102            self.0.request = v.into();
103            self
104        }
105
106        /// Sets all the options, replacing any prior values.
107        pub fn with_options<V: Into<gax::options::RequestOptions>>(mut self, v: V) -> Self {
108            self.0.options = v.into();
109            self
110        }
111
112        /// Sends the request.
113        pub async fn send(self) -> Result<crate::model::CheckResponse> {
114            (*self.0.stub)
115                .check(self.0.request, self.0.options)
116                .await
117                .map(gax::response::Response::into_body)
118        }
119
120        /// Sets the value of [service_name][crate::model::CheckRequest::service_name].
121        pub fn set_service_name<T: Into<std::string::String>>(mut self, v: T) -> Self {
122            self.0.request.service_name = v.into();
123            self
124        }
125
126        /// Sets the value of [service_config_id][crate::model::CheckRequest::service_config_id].
127        pub fn set_service_config_id<T: Into<std::string::String>>(mut self, v: T) -> Self {
128            self.0.request.service_config_id = v.into();
129            self
130        }
131
132        /// Sets the value of [attributes][crate::model::CheckRequest::attributes].
133        pub fn set_attributes<T>(mut self, v: T) -> Self
134        where
135            T: std::convert::Into<rpc_context::model::AttributeContext>,
136        {
137            self.0.request.attributes = std::option::Option::Some(v.into());
138            self
139        }
140
141        /// Sets or clears the value of [attributes][crate::model::CheckRequest::attributes].
142        pub fn set_or_clear_attributes<T>(mut self, v: std::option::Option<T>) -> Self
143        where
144            T: std::convert::Into<rpc_context::model::AttributeContext>,
145        {
146            self.0.request.attributes = v.map(|x| x.into());
147            self
148        }
149
150        /// Sets the value of [resources][crate::model::CheckRequest::resources].
151        pub fn set_resources<T, V>(mut self, v: T) -> Self
152        where
153            T: std::iter::IntoIterator<Item = V>,
154            V: std::convert::Into<crate::model::ResourceInfo>,
155        {
156            use std::iter::Iterator;
157            self.0.request.resources = v.into_iter().map(|i| i.into()).collect();
158            self
159        }
160
161        /// Sets the value of [flags][crate::model::CheckRequest::flags].
162        pub fn set_flags<T: Into<std::string::String>>(mut self, v: T) -> Self {
163            self.0.request.flags = v.into();
164            self
165        }
166    }
167
168    #[doc(hidden)]
169    impl gax::options::internal::RequestBuilder for Check {
170        fn request_options(&mut self) -> &mut gax::options::RequestOptions {
171            &mut self.0.options
172        }
173    }
174
175    /// The request builder for [ServiceController::report][crate::client::ServiceController::report] calls.
176    ///
177    /// # Example
178    /// ```
179    /// # use google_cloud_api_servicecontrol_v2::builder::service_controller::Report;
180    /// # async fn sample() -> gax::Result<()> {
181    ///
182    /// let builder = prepare_request_builder();
183    /// let response = builder.send().await?;
184    /// # Ok(()) }
185    ///
186    /// fn prepare_request_builder() -> Report {
187    ///   # panic!();
188    ///   // ... details omitted ...
189    /// }
190    /// ```
191    #[derive(Clone, Debug)]
192    pub struct Report(RequestBuilder<crate::model::ReportRequest>);
193
194    impl Report {
195        pub(crate) fn new(
196            stub: std::sync::Arc<dyn super::super::stub::dynamic::ServiceController>,
197        ) -> Self {
198            Self(RequestBuilder::new(stub))
199        }
200
201        /// Sets the full request, replacing any prior values.
202        pub fn with_request<V: Into<crate::model::ReportRequest>>(mut self, v: V) -> Self {
203            self.0.request = v.into();
204            self
205        }
206
207        /// Sets all the options, replacing any prior values.
208        pub fn with_options<V: Into<gax::options::RequestOptions>>(mut self, v: V) -> Self {
209            self.0.options = v.into();
210            self
211        }
212
213        /// Sends the request.
214        pub async fn send(self) -> Result<crate::model::ReportResponse> {
215            (*self.0.stub)
216                .report(self.0.request, self.0.options)
217                .await
218                .map(gax::response::Response::into_body)
219        }
220
221        /// Sets the value of [service_name][crate::model::ReportRequest::service_name].
222        pub fn set_service_name<T: Into<std::string::String>>(mut self, v: T) -> Self {
223            self.0.request.service_name = v.into();
224            self
225        }
226
227        /// Sets the value of [service_config_id][crate::model::ReportRequest::service_config_id].
228        pub fn set_service_config_id<T: Into<std::string::String>>(mut self, v: T) -> Self {
229            self.0.request.service_config_id = v.into();
230            self
231        }
232
233        /// Sets the value of [operations][crate::model::ReportRequest::operations].
234        pub fn set_operations<T, V>(mut self, v: T) -> Self
235        where
236            T: std::iter::IntoIterator<Item = V>,
237            V: std::convert::Into<rpc_context::model::AttributeContext>,
238        {
239            use std::iter::Iterator;
240            self.0.request.operations = v.into_iter().map(|i| i.into()).collect();
241            self
242        }
243    }
244
245    #[doc(hidden)]
246    impl gax::options::internal::RequestBuilder for Report {
247        fn request_options(&mut self) -> &mut gax::options::RequestOptions {
248            &mut self.0.options
249        }
250    }
251}