#
google_cloud_pubsub/generated/gapic_dataplane/
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 publisher {
    18    use crate::Result;
    19
    20    /// Common implementation for [crate::client::Publisher] request builders.
    21    #[derive(Clone, Debug)]
    22    pub(crate) struct RequestBuilder<R: std::default::Default> {
    23        stub: std::sync::Arc<dyn super::super::stub::dynamic::Publisher>,
    24        request: R,
    25        options: gax::options::RequestOptions,
    26    }
    27
    28    impl<R> RequestBuilder<R>
    29    where
    30        R: std::default::Default,
    31    {
    32        pub(crate) fn new(
    33            stub: std::sync::Arc<dyn super::super::stub::dynamic::Publisher>,
    34        ) -> Self {
    35            Self {
    36                stub,
    37                request: R::default(),
    38                options: gax::options::RequestOptions::default(),
    39            }
    40        }
    41    }
    42
    43    /// The request builder for [Publisher::publish][crate::client::Publisher::publish] calls.
    44    ///
    45    /// # Example
    46    /// ```
    47    /// # use google_cloud_pubsub::builder::publisher::Publish;
    48    /// # async fn sample() -> gax::Result<()> {
    49    ///
    50    /// let builder = prepare_request_builder();
    51    /// let response = builder.send().await?;
    52    /// # Ok(()) }
    53    ///
    54    /// fn prepare_request_builder() -> Publish {
    55    ///   # panic!();
    56    ///   // ... details omitted ...
    57    /// }
    58    /// ```
    59    #[derive(Clone, Debug)]
    60    pub struct Publish(RequestBuilder<crate::model::PublishRequest>);
    61
    62    impl Publish {
    63        pub(crate) fn new(
    64            stub: std::sync::Arc<dyn super::super::stub::dynamic::Publisher>,
    65        ) -> Self {
    66            Self(RequestBuilder::new(stub))
    67        }
    68
    69        /// Sets the full request, replacing any prior values.
    70        pub fn with_request<V: Into<crate::model::PublishRequest>>(mut self, v: V) -> Self {
    71            self.0.request = v.into();
    72            self
    73        }
    74
    75        /// Sets all the options, replacing any prior values.
    76        pub fn with_options<V: Into<gax::options::RequestOptions>>(mut self, v: V) -> Self {
    77            self.0.options = v.into();
    78            self
    79        }
    80
    81        /// Sends the request.
    82        pub async fn send(self) -> Result<crate::model::PublishResponse> {
    83            (*self.0.stub)
    84                .publish(self.0.request, self.0.options)
    85                .await
    86                .map(gax::response::Response::into_body)
    87        }
    88
    89        /// Sets the value of [topic][crate::model::PublishRequest::topic].
    90        ///
    91        /// This is a **required** field for requests.
    92        pub fn set_topic<T: Into<std::string::String>>(mut self, v: T) -> Self {
    93            self.0.request.topic = v.into();
    94            self
    95        }
    96
    97        /// Sets the value of [messages][crate::model::PublishRequest::messages].
    98        ///
    99        /// This is a **required** field for requests.
    100        pub fn set_messages<T, V>(mut self, v: T) -> Self
    101        where
    102            T: std::iter::IntoIterator<Item = V>,
    103            V: std::convert::Into<crate::model::PubsubMessage>,
    104        {
    105            use std::iter::Iterator;
    106            self.0.request.messages = v.into_iter().map(|i| i.into()).collect();
    107            self
    108        }
    109    }
    110
    111    #[doc(hidden)]
    112    impl gax::options::internal::RequestBuilder for Publish {
    113        fn request_options(&mut self) -> &mut gax::options::RequestOptions {
    114            &mut self.0.options
    115        }
    116    }
    117}
    118
    119pub mod subscriber {
    120    use crate::Result;
    121
    122    /// Common implementation for [crate::client::Subscriber] request builders.
    123    #[derive(Clone, Debug)]
    124    pub(crate) struct RequestBuilder<R: std::default::Default> {
    125        stub: std::sync::Arc<dyn super::super::stub::dynamic::Subscriber>,
    126        request: R,
    127        options: gax::options::RequestOptions,
    128    }
    129
    130    impl<R> RequestBuilder<R>
    131    where
    132        R: std::default::Default,
    133    {
    134        pub(crate) fn new(
    135            stub: std::sync::Arc<dyn super::super::stub::dynamic::Subscriber>,
    136        ) -> Self {
    137            Self {
    138                stub,
    139                request: R::default(),
    140                options: gax::options::RequestOptions::default(),
    141            }
    142        }
    143    }
    144
    145    /// The request builder for [Subscriber::modify_ack_deadline][crate::client::Subscriber::modify_ack_deadline] calls.
    146    ///
    147    /// # Example
    148    /// ```
    149    /// # use google_cloud_pubsub::builder::subscriber::ModifyAckDeadline;
    150    /// # async fn sample() -> gax::Result<()> {
    151    ///
    152    /// let builder = prepare_request_builder();
    153    /// let response = builder.send().await?;
    154    /// # Ok(()) }
    155    ///
    156    /// fn prepare_request_builder() -> ModifyAckDeadline {
    157    ///   # panic!();
    158    ///   // ... details omitted ...
    159    /// }
    160    /// ```
    161    #[derive(Clone, Debug)]
    162    pub struct ModifyAckDeadline(RequestBuilder<crate::model::ModifyAckDeadlineRequest>);
    163
    164    impl ModifyAckDeadline {
    165        pub(crate) fn new(
    166            stub: std::sync::Arc<dyn super::super::stub::dynamic::Subscriber>,
    167        ) -> Self {
    168            Self(RequestBuilder::new(stub))
    169        }
    170
    171        /// Sets the full request, replacing any prior values.
    172        pub fn with_request<V: Into<crate::model::ModifyAckDeadlineRequest>>(
    173            mut self,
    174            v: V,
    175        ) -> Self {
    176            self.0.request = v.into();
    177            self
    178        }
    179
    180        /// Sets all the options, replacing any prior values.
    181        pub fn with_options<V: Into<gax::options::RequestOptions>>(mut self, v: V) -> Self {
    182            self.0.options = v.into();
    183            self
    184        }
    185
    186        /// Sends the request.
    187        pub async fn send(self) -> Result<()> {
    188            (*self.0.stub)
    189                .modify_ack_deadline(self.0.request, self.0.options)
    190                .await
    191                .map(gax::response::Response::into_body)
    192        }
    193
    194        /// Sets the value of [subscription][crate::model::ModifyAckDeadlineRequest::subscription].
    195        ///
    196        /// This is a **required** field for requests.
    197        pub fn set_subscription<T: Into<std::string::String>>(mut self, v: T) -> Self {
    198            self.0.request.subscription = v.into();
    199            self
    200        }
    201
    202        /// Sets the value of [ack_ids][crate::model::ModifyAckDeadlineRequest::ack_ids].
    203        ///
    204        /// This is a **required** field for requests.
    205        pub fn set_ack_ids<T, V>(mut self, v: T) -> Self
    206        where
    207            T: std::iter::IntoIterator<Item = V>,
    208            V: std::convert::Into<std::string::String>,
    209        {
    210            use std::iter::Iterator;
    211            self.0.request.ack_ids = v.into_iter().map(|i| i.into()).collect();
    212            self
    213        }
    214
    215        /// Sets the value of [ack_deadline_seconds][crate::model::ModifyAckDeadlineRequest::ack_deadline_seconds].
    216        ///
    217        /// This is a **required** field for requests.
    218        pub fn set_ack_deadline_seconds<T: Into<i32>>(mut self, v: T) -> Self {
    219            self.0.request.ack_deadline_seconds = v.into();
    220            self
    221        }
    222    }
    223
    224    #[doc(hidden)]
    225    impl gax::options::internal::RequestBuilder for ModifyAckDeadline {
    226        fn request_options(&mut self) -> &mut gax::options::RequestOptions {
    227            &mut self.0.options
    228        }
    229    }
    230
    231    /// The request builder for [Subscriber::acknowledge][crate::client::Subscriber::acknowledge] calls.
    232    ///
    233    /// # Example
    234    /// ```
    235    /// # use google_cloud_pubsub::builder::subscriber::Acknowledge;
    236    /// # async fn sample() -> gax::Result<()> {
    237    ///
    238    /// let builder = prepare_request_builder();
    239    /// let response = builder.send().await?;
    240    /// # Ok(()) }
    241    ///
    242    /// fn prepare_request_builder() -> Acknowledge {
    243    ///   # panic!();
    244    ///   // ... details omitted ...
    245    /// }
    246    /// ```
    247    #[derive(Clone, Debug)]
    248    pub struct Acknowledge(RequestBuilder<crate::model::AcknowledgeRequest>);
    249
    250    impl Acknowledge {
    251        pub(crate) fn new(
    252            stub: std::sync::Arc<dyn super::super::stub::dynamic::Subscriber>,
    253        ) -> Self {
    254            Self(RequestBuilder::new(stub))
    255        }
    256
    257        /// Sets the full request, replacing any prior values.
    258        pub fn with_request<V: Into<crate::model::AcknowledgeRequest>>(mut self, v: V) -> Self {
    259            self.0.request = v.into();
    260            self
    261        }
    262
    263        /// Sets all the options, replacing any prior values.
    264        pub fn with_options<V: Into<gax::options::RequestOptions>>(mut self, v: V) -> Self {
    265            self.0.options = v.into();
    266            self
    267        }
    268
    269        /// Sends the request.
    270        pub async fn send(self) -> Result<()> {
    271            (*self.0.stub)
    272                .acknowledge(self.0.request, self.0.options)
    273                .await
    274                .map(gax::response::Response::into_body)
    275        }
    276
    277        /// Sets the value of [subscription][crate::model::AcknowledgeRequest::subscription].
    278        ///
    279        /// This is a **required** field for requests.
    280        pub fn set_subscription<T: Into<std::string::String>>(mut self, v: T) -> Self {
    281            self.0.request.subscription = v.into();
    282            self
    283        }
    284
    285        /// Sets the value of [ack_ids][crate::model::AcknowledgeRequest::ack_ids].
    286        ///
    287        /// This is a **required** field for requests.
    288        pub fn set_ack_ids<T, V>(mut self, v: T) -> Self
    289        where
    290            T: std::iter::IntoIterator<Item = V>,
    291            V: std::convert::Into<std::string::String>,
    292        {
    293            use std::iter::Iterator;
    294            self.0.request.ack_ids = v.into_iter().map(|i| i.into()).collect();
    295            self
    296        }
    297    }
    298
    299    #[doc(hidden)]
    300    impl gax::options::internal::RequestBuilder for Acknowledge {
    301        fn request_options(&mut self) -> &mut gax::options::RequestOptions {
    302            &mut self.0.options
    303        }
    304    }
    305}