pub trait Publisher<T>: Send + Sync {
// Required methods
fn publish_with(
&self,
data: &T,
options: PublishOptions,
) -> impl Future<Output = Result<String, Error>> + Send;
fn publish_batch(
&self,
messages: &[BatchMessage<'_, T>],
) -> impl Future<Output = Result<Vec<String>, BatchError>> + Send;
fn name(&self) -> &'static str;
// Provided method
fn publish(
&self,
data: &T,
) -> impl Future<Output = Result<String, Error>> + Send { ... }
}Expand description
Trait for publishing messages of type T to an unordered topic.
Implemented by TopicRef when granted perms::Publisher. Accept
&impl Publisher<T> in helper functions so they work with references and
test fakes:
async fn signed_up(topic: &impl Publisher<String>, user: &String) -> Result<(), encore::Error> {
topic.publish(user).await?;
Ok(())
}
signed_up(&SIGNUPS.reference::<perms::Publisher>(), &user).await?;Topic intentionally does not implement this trait so Encore can track
permissions statically via Topic::reference:
ⓘ
signed_up(&SIGNUPS).await;Methods return impl Future + Send (making the trait compatible with
spawned tasks, though not dyn-compatible).
Required Methods§
Sourcefn publish_with(
&self,
data: &T,
options: PublishOptions,
) -> impl Future<Output = Result<String, Error>> + Send
fn publish_with( &self, data: &T, options: PublishOptions, ) -> impl Future<Output = Result<String, Error>> + Send
See Topic::publish_with.
Sourcefn publish_batch(
&self,
messages: &[BatchMessage<'_, T>],
) -> impl Future<Output = Result<Vec<String>, BatchError>> + Send
fn publish_batch( &self, messages: &[BatchMessage<'_, T>], ) -> impl Future<Output = Result<Vec<String>, BatchError>> + Send
See Topic::publish_batch.
Provided Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".