fundamentum_sdk_mqtt/
publisher.rs

1use std::error::Error;
2
3use crate::{PublishOptions, Publishable};
4
5/// Types which may publish publishable data.
6pub trait Publisher: Clone {
7    /// Error type related to a failed publish.
8    type Error: Error;
9
10    /// Publish the publishable structure without overriding [`PublishOptions`].
11    fn publish<P>(&self, publishable: P) -> impl Future<Output = Result<(), Self::Error>> + Send
12    where
13        P: Publishable + Send + 'static,
14    {
15        self.publish_with(publishable, PublishOptions::default())
16    }
17
18    /// Publish the publishable structure with [`PublishOptions`] overriding all
19    /// other options, including the [`Publishable::publish_overrides()`]. If no
20    /// options are provided, fallback options shall be used.
21    fn publish_with<P>(
22        &self,
23        publishable: P,
24        options: PublishOptions,
25    ) -> impl Future<Output = Result<(), Self::Error>> + Send
26    where
27        P: Publishable + Send + 'static;
28}