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    /// # tokio_test::block_on(async {
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    /// # gax::client_builder::Result::<()>::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    /// ```no_run
78    /// # use google_cloud_api_servicecontrol_v2::builder;
79    /// use builder::service_controller::Check;
80    /// # tokio_test::block_on(async {
81    ///
82    /// let builder = prepare_request_builder();
83    /// let response = builder.send().await?;
84    /// # gax::Result::<()>::Ok(()) });
85    ///
86    /// fn prepare_request_builder() -> Check {
87    ///   # panic!();
88    ///   // ... details omitted ...
89    /// }
90    /// ```
91    #[derive(Clone, Debug)]
92    pub struct Check(RequestBuilder<crate::model::CheckRequest>);
93
94    impl Check {
95        pub(crate) fn new(
96            stub: std::sync::Arc<dyn super::super::stub::dynamic::ServiceController>,
97        ) -> Self {
98            Self(RequestBuilder::new(stub))
99        }
100
101        /// Sets the full request, replacing any prior values.
102        pub fn with_request<V: Into<crate::model::CheckRequest>>(mut self, v: V) -> Self {
103            self.0.request = v.into();
104            self
105        }
106
107        /// Sets all the options, replacing any prior values.
108        pub fn with_options<V: Into<gax::options::RequestOptions>>(mut self, v: V) -> Self {
109            self.0.options = v.into();
110            self
111        }
112
113        /// Sends the request.
114        pub async fn send(self) -> Result<crate::model::CheckResponse> {
115            (*self.0.stub)
116                .check(self.0.request, self.0.options)
117                .await
118                .map(gax::response::Response::into_body)
119        }
120
121        /// Sets the value of [service_name][crate::model::CheckRequest::service_name].
122        pub fn set_service_name<T: Into<std::string::String>>(mut self, v: T) -> Self {
123            self.0.request.service_name = v.into();
124            self
125        }
126
127        /// Sets the value of [service_config_id][crate::model::CheckRequest::service_config_id].
128        pub fn set_service_config_id<T: Into<std::string::String>>(mut self, v: T) -> Self {
129            self.0.request.service_config_id = v.into();
130            self
131        }
132
133        /// Sets the value of [attributes][crate::model::CheckRequest::attributes].
134        pub fn set_attributes<T>(mut self, v: T) -> Self
135        where
136            T: std::convert::Into<rpc_context::model::AttributeContext>,
137        {
138            self.0.request.attributes = std::option::Option::Some(v.into());
139            self
140        }
141
142        /// Sets or clears the value of [attributes][crate::model::CheckRequest::attributes].
143        pub fn set_or_clear_attributes<T>(mut self, v: std::option::Option<T>) -> Self
144        where
145            T: std::convert::Into<rpc_context::model::AttributeContext>,
146        {
147            self.0.request.attributes = v.map(|x| x.into());
148            self
149        }
150
151        /// Sets the value of [resources][crate::model::CheckRequest::resources].
152        pub fn set_resources<T, V>(mut self, v: T) -> Self
153        where
154            T: std::iter::IntoIterator<Item = V>,
155            V: std::convert::Into<crate::model::ResourceInfo>,
156        {
157            use std::iter::Iterator;
158            self.0.request.resources = v.into_iter().map(|i| i.into()).collect();
159            self
160        }
161
162        /// Sets the value of [flags][crate::model::CheckRequest::flags].
163        pub fn set_flags<T: Into<std::string::String>>(mut self, v: T) -> Self {
164            self.0.request.flags = v.into();
165            self
166        }
167    }
168
169    #[doc(hidden)]
170    impl gax::options::internal::RequestBuilder for Check {
171        fn request_options(&mut self) -> &mut gax::options::RequestOptions {
172            &mut self.0.options
173        }
174    }
175
176    /// The request builder for [ServiceController::report][crate::client::ServiceController::report] calls.
177    ///
178    /// # Example
179    /// ```no_run
180    /// # use google_cloud_api_servicecontrol_v2::builder;
181    /// use builder::service_controller::Report;
182    /// # tokio_test::block_on(async {
183    ///
184    /// let builder = prepare_request_builder();
185    /// let response = builder.send().await?;
186    /// # gax::Result::<()>::Ok(()) });
187    ///
188    /// fn prepare_request_builder() -> Report {
189    ///   # panic!();
190    ///   // ... details omitted ...
191    /// }
192    /// ```
193    #[derive(Clone, Debug)]
194    pub struct Report(RequestBuilder<crate::model::ReportRequest>);
195
196    impl Report {
197        pub(crate) fn new(
198            stub: std::sync::Arc<dyn super::super::stub::dynamic::ServiceController>,
199        ) -> Self {
200            Self(RequestBuilder::new(stub))
201        }
202
203        /// Sets the full request, replacing any prior values.
204        pub fn with_request<V: Into<crate::model::ReportRequest>>(mut self, v: V) -> Self {
205            self.0.request = v.into();
206            self
207        }
208
209        /// Sets all the options, replacing any prior values.
210        pub fn with_options<V: Into<gax::options::RequestOptions>>(mut self, v: V) -> Self {
211            self.0.options = v.into();
212            self
213        }
214
215        /// Sends the request.
216        pub async fn send(self) -> Result<crate::model::ReportResponse> {
217            (*self.0.stub)
218                .report(self.0.request, self.0.options)
219                .await
220                .map(gax::response::Response::into_body)
221        }
222
223        /// Sets the value of [service_name][crate::model::ReportRequest::service_name].
224        pub fn set_service_name<T: Into<std::string::String>>(mut self, v: T) -> Self {
225            self.0.request.service_name = v.into();
226            self
227        }
228
229        /// Sets the value of [service_config_id][crate::model::ReportRequest::service_config_id].
230        pub fn set_service_config_id<T: Into<std::string::String>>(mut self, v: T) -> Self {
231            self.0.request.service_config_id = v.into();
232            self
233        }
234
235        /// Sets the value of [operations][crate::model::ReportRequest::operations].
236        pub fn set_operations<T, V>(mut self, v: T) -> Self
237        where
238            T: std::iter::IntoIterator<Item = V>,
239            V: std::convert::Into<rpc_context::model::AttributeContext>,
240        {
241            use std::iter::Iterator;
242            self.0.request.operations = v.into_iter().map(|i| i.into()).collect();
243            self
244        }
245    }
246
247    #[doc(hidden)]
248    impl gax::options::internal::RequestBuilder for Report {
249        fn request_options(&mut self) -> &mut gax::options::RequestOptions {
250            &mut self.0.options
251        }
252    }
253}