Skip to main content

google_cloud_trace_v1/
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 trace_service {
18    use crate::Result;
19
20    /// A builder for [TraceService][crate::client::TraceService].
21    ///
22    /// ```
23    /// # async fn sample() -> gax::client_builder::Result<()> {
24    /// # use google_cloud_trace_v1::*;
25    /// # use builder::trace_service::ClientBuilder;
26    /// # use client::TraceService;
27    /// let builder : ClientBuilder = TraceService::builder();
28    /// let client = builder
29    ///     .with_endpoint("https://cloudtrace.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::TraceService;
38        pub struct Factory;
39        impl gax::client_builder::internal::ClientFactory for Factory {
40            type Client = TraceService;
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::TraceService] 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::TraceService>,
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::TraceService>,
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 [TraceService::list_traces][crate::client::TraceService::list_traces] calls.
75    ///
76    /// # Example
77    /// ```
78    /// # use google_cloud_trace_v1::builder::trace_service::ListTraces;
79    /// # async fn sample() -> gax::Result<()> {
80    /// use gax::paginator::ItemPaginator;
81    ///
82    /// let builder = prepare_request_builder();
83    /// let mut items = builder.by_item();
84    /// while let Some(result) = items.next().await {
85    ///   let item = result?;
86    /// }
87    /// # Ok(()) }
88    ///
89    /// fn prepare_request_builder() -> ListTraces {
90    ///   # panic!();
91    ///   // ... details omitted ...
92    /// }
93    /// ```
94    #[derive(Clone, Debug)]
95    pub struct ListTraces(RequestBuilder<crate::model::ListTracesRequest>);
96
97    impl ListTraces {
98        pub(crate) fn new(
99            stub: std::sync::Arc<dyn super::super::stub::dynamic::TraceService>,
100        ) -> Self {
101            Self(RequestBuilder::new(stub))
102        }
103
104        /// Sets the full request, replacing any prior values.
105        pub fn with_request<V: Into<crate::model::ListTracesRequest>>(mut self, v: V) -> Self {
106            self.0.request = v.into();
107            self
108        }
109
110        /// Sets all the options, replacing any prior values.
111        pub fn with_options<V: Into<gax::options::RequestOptions>>(mut self, v: V) -> Self {
112            self.0.options = v.into();
113            self
114        }
115
116        /// Sends the request.
117        pub async fn send(self) -> Result<crate::model::ListTracesResponse> {
118            (*self.0.stub)
119                .list_traces(self.0.request, self.0.options)
120                .await
121                .map(gax::response::Response::into_body)
122        }
123
124        /// Streams each page in the collection.
125        pub fn by_page(
126            self,
127        ) -> impl gax::paginator::Paginator<crate::model::ListTracesResponse, gax::error::Error>
128        {
129            use std::clone::Clone;
130            let token = self.0.request.page_token.clone();
131            let execute = move |token: String| {
132                let mut builder = self.clone();
133                builder.0.request = builder.0.request.set_page_token(token);
134                builder.send()
135            };
136            gax::paginator::internal::new_paginator(token, execute)
137        }
138
139        /// Streams each item in the collection.
140        pub fn by_item(
141            self,
142        ) -> impl gax::paginator::ItemPaginator<crate::model::ListTracesResponse, gax::error::Error>
143        {
144            use gax::paginator::Paginator;
145            self.by_page().items()
146        }
147
148        /// Sets the value of [project_id][crate::model::ListTracesRequest::project_id].
149        ///
150        /// This is a **required** field for requests.
151        pub fn set_project_id<T: Into<std::string::String>>(mut self, v: T) -> Self {
152            self.0.request.project_id = v.into();
153            self
154        }
155
156        /// Sets the value of [view][crate::model::ListTracesRequest::view].
157        pub fn set_view<T: Into<crate::model::list_traces_request::ViewType>>(
158            mut self,
159            v: T,
160        ) -> Self {
161            self.0.request.view = v.into();
162            self
163        }
164
165        /// Sets the value of [page_size][crate::model::ListTracesRequest::page_size].
166        pub fn set_page_size<T: Into<i32>>(mut self, v: T) -> Self {
167            self.0.request.page_size = v.into();
168            self
169        }
170
171        /// Sets the value of [page_token][crate::model::ListTracesRequest::page_token].
172        pub fn set_page_token<T: Into<std::string::String>>(mut self, v: T) -> Self {
173            self.0.request.page_token = v.into();
174            self
175        }
176
177        /// Sets the value of [start_time][crate::model::ListTracesRequest::start_time].
178        pub fn set_start_time<T>(mut self, v: T) -> Self
179        where
180            T: std::convert::Into<wkt::Timestamp>,
181        {
182            self.0.request.start_time = std::option::Option::Some(v.into());
183            self
184        }
185
186        /// Sets or clears the value of [start_time][crate::model::ListTracesRequest::start_time].
187        pub fn set_or_clear_start_time<T>(mut self, v: std::option::Option<T>) -> Self
188        where
189            T: std::convert::Into<wkt::Timestamp>,
190        {
191            self.0.request.start_time = v.map(|x| x.into());
192            self
193        }
194
195        /// Sets the value of [end_time][crate::model::ListTracesRequest::end_time].
196        pub fn set_end_time<T>(mut self, v: T) -> Self
197        where
198            T: std::convert::Into<wkt::Timestamp>,
199        {
200            self.0.request.end_time = std::option::Option::Some(v.into());
201            self
202        }
203
204        /// Sets or clears the value of [end_time][crate::model::ListTracesRequest::end_time].
205        pub fn set_or_clear_end_time<T>(mut self, v: std::option::Option<T>) -> Self
206        where
207            T: std::convert::Into<wkt::Timestamp>,
208        {
209            self.0.request.end_time = v.map(|x| x.into());
210            self
211        }
212
213        /// Sets the value of [filter][crate::model::ListTracesRequest::filter].
214        pub fn set_filter<T: Into<std::string::String>>(mut self, v: T) -> Self {
215            self.0.request.filter = v.into();
216            self
217        }
218
219        /// Sets the value of [order_by][crate::model::ListTracesRequest::order_by].
220        pub fn set_order_by<T: Into<std::string::String>>(mut self, v: T) -> Self {
221            self.0.request.order_by = v.into();
222            self
223        }
224    }
225
226    #[doc(hidden)]
227    impl gax::options::internal::RequestBuilder for ListTraces {
228        fn request_options(&mut self) -> &mut gax::options::RequestOptions {
229            &mut self.0.options
230        }
231    }
232
233    /// The request builder for [TraceService::get_trace][crate::client::TraceService::get_trace] calls.
234    ///
235    /// # Example
236    /// ```
237    /// # use google_cloud_trace_v1::builder::trace_service::GetTrace;
238    /// # async fn sample() -> gax::Result<()> {
239    ///
240    /// let builder = prepare_request_builder();
241    /// let response = builder.send().await?;
242    /// # Ok(()) }
243    ///
244    /// fn prepare_request_builder() -> GetTrace {
245    ///   # panic!();
246    ///   // ... details omitted ...
247    /// }
248    /// ```
249    #[derive(Clone, Debug)]
250    pub struct GetTrace(RequestBuilder<crate::model::GetTraceRequest>);
251
252    impl GetTrace {
253        pub(crate) fn new(
254            stub: std::sync::Arc<dyn super::super::stub::dynamic::TraceService>,
255        ) -> Self {
256            Self(RequestBuilder::new(stub))
257        }
258
259        /// Sets the full request, replacing any prior values.
260        pub fn with_request<V: Into<crate::model::GetTraceRequest>>(mut self, v: V) -> Self {
261            self.0.request = v.into();
262            self
263        }
264
265        /// Sets all the options, replacing any prior values.
266        pub fn with_options<V: Into<gax::options::RequestOptions>>(mut self, v: V) -> Self {
267            self.0.options = v.into();
268            self
269        }
270
271        /// Sends the request.
272        pub async fn send(self) -> Result<crate::model::Trace> {
273            (*self.0.stub)
274                .get_trace(self.0.request, self.0.options)
275                .await
276                .map(gax::response::Response::into_body)
277        }
278
279        /// Sets the value of [project_id][crate::model::GetTraceRequest::project_id].
280        ///
281        /// This is a **required** field for requests.
282        pub fn set_project_id<T: Into<std::string::String>>(mut self, v: T) -> Self {
283            self.0.request.project_id = v.into();
284            self
285        }
286
287        /// Sets the value of [trace_id][crate::model::GetTraceRequest::trace_id].
288        ///
289        /// This is a **required** field for requests.
290        pub fn set_trace_id<T: Into<std::string::String>>(mut self, v: T) -> Self {
291            self.0.request.trace_id = v.into();
292            self
293        }
294    }
295
296    #[doc(hidden)]
297    impl gax::options::internal::RequestBuilder for GetTrace {
298        fn request_options(&mut self) -> &mut gax::options::RequestOptions {
299            &mut self.0.options
300        }
301    }
302
303    /// The request builder for [TraceService::patch_traces][crate::client::TraceService::patch_traces] calls.
304    ///
305    /// # Example
306    /// ```
307    /// # use google_cloud_trace_v1::builder::trace_service::PatchTraces;
308    /// # async fn sample() -> gax::Result<()> {
309    ///
310    /// let builder = prepare_request_builder();
311    /// let response = builder.send().await?;
312    /// # Ok(()) }
313    ///
314    /// fn prepare_request_builder() -> PatchTraces {
315    ///   # panic!();
316    ///   // ... details omitted ...
317    /// }
318    /// ```
319    #[derive(Clone, Debug)]
320    pub struct PatchTraces(RequestBuilder<crate::model::PatchTracesRequest>);
321
322    impl PatchTraces {
323        pub(crate) fn new(
324            stub: std::sync::Arc<dyn super::super::stub::dynamic::TraceService>,
325        ) -> Self {
326            Self(RequestBuilder::new(stub))
327        }
328
329        /// Sets the full request, replacing any prior values.
330        pub fn with_request<V: Into<crate::model::PatchTracesRequest>>(mut self, v: V) -> Self {
331            self.0.request = v.into();
332            self
333        }
334
335        /// Sets all the options, replacing any prior values.
336        pub fn with_options<V: Into<gax::options::RequestOptions>>(mut self, v: V) -> Self {
337            self.0.options = v.into();
338            self
339        }
340
341        /// Sends the request.
342        pub async fn send(self) -> Result<()> {
343            (*self.0.stub)
344                .patch_traces(self.0.request, self.0.options)
345                .await
346                .map(gax::response::Response::into_body)
347        }
348
349        /// Sets the value of [project_id][crate::model::PatchTracesRequest::project_id].
350        ///
351        /// This is a **required** field for requests.
352        pub fn set_project_id<T: Into<std::string::String>>(mut self, v: T) -> Self {
353            self.0.request.project_id = v.into();
354            self
355        }
356
357        /// Sets the value of [traces][crate::model::PatchTracesRequest::traces].
358        ///
359        /// This is a **required** field for requests.
360        pub fn set_traces<T>(mut self, v: T) -> Self
361        where
362            T: std::convert::Into<crate::model::Traces>,
363        {
364            self.0.request.traces = std::option::Option::Some(v.into());
365            self
366        }
367
368        /// Sets or clears the value of [traces][crate::model::PatchTracesRequest::traces].
369        ///
370        /// This is a **required** field for requests.
371        pub fn set_or_clear_traces<T>(mut self, v: std::option::Option<T>) -> Self
372        where
373            T: std::convert::Into<crate::model::Traces>,
374        {
375            self.0.request.traces = v.map(|x| x.into());
376            self
377        }
378    }
379
380    #[doc(hidden)]
381    impl gax::options::internal::RequestBuilder for PatchTraces {
382        fn request_options(&mut self) -> &mut gax::options::RequestOptions {
383            &mut self.0.options
384        }
385    }
386}