google-cloud-pubsub 0.33.2

Google Cloud Client Libraries for Rust - Pub/Sub
Documentation
// Copyright 2025 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Code generated by sidekick. DO NOT EDIT.

pub mod publisher {
    use crate::Result;

    /// Common implementation for [crate::client::Publisher] request builders.
    #[derive(Clone, Debug)]
    pub(crate) struct RequestBuilder<R: std::default::Default> {
        stub: std::sync::Arc<dyn super::super::stub::dynamic::Publisher>,
        request: R,
        options: crate::RequestOptions,
    }

    impl<R> RequestBuilder<R>
    where
        R: std::default::Default,
    {
        pub(crate) fn new(
            stub: std::sync::Arc<dyn super::super::stub::dynamic::Publisher>,
        ) -> Self {
            Self {
                stub,
                request: R::default(),
                options: crate::RequestOptions::default(),
            }
        }
    }

    /// The request builder for [Publisher::publish][crate::client::Publisher::publish] calls.
    #[derive(Clone, Debug)]
    pub(crate) struct Publish(RequestBuilder<crate::model::PublishRequest>);

    impl Publish {
        pub(crate) fn new(
            stub: std::sync::Arc<dyn super::super::stub::dynamic::Publisher>,
        ) -> Self {
            Self(RequestBuilder::new(stub))
        }

        /// Sets the full request, replacing any prior values.
        pub fn with_request<V: Into<crate::model::PublishRequest>>(mut self, v: V) -> Self {
            self.0.request = v.into();
            self
        }

        /// Sets all the options, replacing any prior values.
        pub fn with_options<V: Into<crate::RequestOptions>>(mut self, v: V) -> Self {
            self.0.options = v.into();
            self
        }

        /// Sends the request.
        pub async fn send(self) -> Result<crate::model::PublishResponse> {
            (*self.0.stub)
                .publish(self.0.request, self.0.options)
                .await
                .map(crate::Response::into_body)
        }

        /// Sets the value of [topic][crate::model::PublishRequest::topic].
        ///
        /// This is a **required** field for requests.
        pub fn set_topic<T: Into<std::string::String>>(mut self, v: T) -> Self {
            self.0.request.topic = v.into();
            self
        }

        /// Sets the value of [messages][crate::model::PublishRequest::messages].
        ///
        /// This is a **required** field for requests.
        pub fn set_messages<T, V>(mut self, v: T) -> Self
        where
            T: std::iter::IntoIterator<Item = V>,
            V: std::convert::Into<crate::model::PubsubMessage>,
        {
            use std::iter::Iterator;
            self.0.request.messages = v.into_iter().map(|i| i.into()).collect();
            self
        }
    }

    #[doc(hidden)]
    impl crate::RequestBuilder for Publish {
        fn request_options(&mut self) -> &mut crate::RequestOptions {
            &mut self.0.options
        }
    }
}

pub mod subscriber {
    use crate::Result;

    /// Common implementation for [crate::client::Subscriber] request builders.
    #[derive(Clone, Debug)]
    pub(crate) struct RequestBuilder<R: std::default::Default> {
        stub: std::sync::Arc<dyn super::super::stub::dynamic::Subscriber>,
        request: R,
        options: crate::RequestOptions,
    }

    impl<R> RequestBuilder<R>
    where
        R: std::default::Default,
    {
        pub(crate) fn new(
            stub: std::sync::Arc<dyn super::super::stub::dynamic::Subscriber>,
        ) -> Self {
            Self {
                stub,
                request: R::default(),
                options: crate::RequestOptions::default(),
            }
        }
    }

    /// The request builder for [Subscriber::modify_ack_deadline][crate::client::Subscriber::modify_ack_deadline] calls.
    #[derive(Clone, Debug)]
    pub(crate) struct ModifyAckDeadline(RequestBuilder<crate::model::ModifyAckDeadlineRequest>);

    impl ModifyAckDeadline {
        pub(crate) fn new(
            stub: std::sync::Arc<dyn super::super::stub::dynamic::Subscriber>,
        ) -> Self {
            Self(RequestBuilder::new(stub))
        }

        /// Sets the full request, replacing any prior values.
        pub fn with_request<V: Into<crate::model::ModifyAckDeadlineRequest>>(
            mut self,
            v: V,
        ) -> Self {
            self.0.request = v.into();
            self
        }

        /// Sets all the options, replacing any prior values.
        pub fn with_options<V: Into<crate::RequestOptions>>(mut self, v: V) -> Self {
            self.0.options = v.into();
            self
        }

        /// Sends the request.
        pub async fn send(self) -> Result<()> {
            (*self.0.stub)
                .modify_ack_deadline(self.0.request, self.0.options)
                .await
                .map(crate::Response::into_body)
        }

        /// Sets the value of [subscription][crate::model::ModifyAckDeadlineRequest::subscription].
        ///
        /// This is a **required** field for requests.
        pub fn set_subscription<T: Into<std::string::String>>(mut self, v: T) -> Self {
            self.0.request.subscription = v.into();
            self
        }

        /// Sets the value of [ack_ids][crate::model::ModifyAckDeadlineRequest::ack_ids].
        ///
        /// This is a **required** field for requests.
        pub fn set_ack_ids<T, V>(mut self, v: T) -> Self
        where
            T: std::iter::IntoIterator<Item = V>,
            V: std::convert::Into<std::string::String>,
        {
            use std::iter::Iterator;
            self.0.request.ack_ids = v.into_iter().map(|i| i.into()).collect();
            self
        }

        /// Sets the value of [ack_deadline_seconds][crate::model::ModifyAckDeadlineRequest::ack_deadline_seconds].
        ///
        /// This is a **required** field for requests.
        pub fn set_ack_deadline_seconds<T: Into<i32>>(mut self, v: T) -> Self {
            self.0.request.ack_deadline_seconds = v.into();
            self
        }
    }

    #[doc(hidden)]
    impl crate::RequestBuilder for ModifyAckDeadline {
        fn request_options(&mut self) -> &mut crate::RequestOptions {
            &mut self.0.options
        }
    }

    /// The request builder for [Subscriber::acknowledge][crate::client::Subscriber::acknowledge] calls.
    #[derive(Clone, Debug)]
    pub(crate) struct Acknowledge(RequestBuilder<crate::model::AcknowledgeRequest>);

    impl Acknowledge {
        pub(crate) fn new(
            stub: std::sync::Arc<dyn super::super::stub::dynamic::Subscriber>,
        ) -> Self {
            Self(RequestBuilder::new(stub))
        }

        /// Sets the full request, replacing any prior values.
        pub fn with_request<V: Into<crate::model::AcknowledgeRequest>>(mut self, v: V) -> Self {
            self.0.request = v.into();
            self
        }

        /// Sets all the options, replacing any prior values.
        pub fn with_options<V: Into<crate::RequestOptions>>(mut self, v: V) -> Self {
            self.0.options = v.into();
            self
        }

        /// Sends the request.
        pub async fn send(self) -> Result<()> {
            (*self.0.stub)
                .acknowledge(self.0.request, self.0.options)
                .await
                .map(crate::Response::into_body)
        }

        /// Sets the value of [subscription][crate::model::AcknowledgeRequest::subscription].
        ///
        /// This is a **required** field for requests.
        pub fn set_subscription<T: Into<std::string::String>>(mut self, v: T) -> Self {
            self.0.request.subscription = v.into();
            self
        }

        /// Sets the value of [ack_ids][crate::model::AcknowledgeRequest::ack_ids].
        ///
        /// This is a **required** field for requests.
        pub fn set_ack_ids<T, V>(mut self, v: T) -> Self
        where
            T: std::iter::IntoIterator<Item = V>,
            V: std::convert::Into<std::string::String>,
        {
            use std::iter::Iterator;
            self.0.request.ack_ids = v.into_iter().map(|i| i.into()).collect();
            self
        }
    }

    #[doc(hidden)]
    impl crate::RequestBuilder for Acknowledge {
        fn request_options(&mut self) -> &mut crate::RequestOptions {
            &mut self.0.options
        }
    }
}