Skip to main content

Publisher

Trait Publisher 

Source
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§

Source

fn publish_with( &self, data: &T, options: PublishOptions, ) -> impl Future<Output = Result<String, Error>> + Send

Source

fn publish_batch( &self, messages: &[BatchMessage<'_, T>], ) -> impl Future<Output = Result<Vec<String>, BatchError>> + Send

Source

fn name(&self) -> &'static str

Returns the name of the topic.

Provided Methods§

Source

fn publish( &self, data: &T, ) -> impl Future<Output = Result<String, Error>> + Send

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§