pub mod publisher {
use crate::Result;
#[derive(Clone, Debug)]
pub(crate) struct RequestBuilder<R: std::default::Default> {
stub: std::sync::Arc<dyn super::super::stub::dynamic::Publisher>,
request: R,
options: gax::options::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: gax::options::RequestOptions::default(),
}
}
}
#[derive(Clone, Debug)]
pub 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))
}
pub fn with_request<V: Into<crate::model::PublishRequest>>(mut self, v: V) -> Self {
self.0.request = v.into();
self
}
pub fn with_options<V: Into<gax::options::RequestOptions>>(mut self, v: V) -> Self {
self.0.options = v.into();
self
}
pub async fn send(self) -> Result<crate::model::PublishResponse> {
(*self.0.stub)
.publish(self.0.request, self.0.options)
.await
.map(gax::response::Response::into_body)
}
pub fn set_topic<T: Into<std::string::String>>(mut self, v: T) -> Self {
self.0.request.topic = v.into();
self
}
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 gax::options::internal::RequestBuilder for Publish {
fn request_options(&mut self) -> &mut gax::options::RequestOptions {
&mut self.0.options
}
}
}