fundamentum_sdk_mqtt/
publishable.rs

1use bytes::Bytes;
2
3use crate::{Device, Error, PublishOptions};
4
5/// Types which may be published by a publisher to a MQTT broker.
6pub trait Publishable {
7    /// This trait's error type.
8    ///
9    /// Must be convertible into this library's own error type.
10    type Error: Into<Error>;
11
12    /// Return the MQTT topic.
13    fn topic(&self, device: &Device) -> impl Into<String> + Send;
14
15    /// Return the payload to publish.
16    ///
17    /// # Errors
18    ///
19    /// May return an error if there is a failure while encoding the payload.
20    fn payload(&self) -> Result<impl Into<Bytes> + Send, Self::Error>;
21
22    /// Return the [`PublishOptions`] overrides for this [`Publishable`].
23    ///
24    /// These overrides are part of an override mechanism to set the options
25    /// for the `Publisher` trait implementor. These `PublishOptions` may be
26    /// overriden by the caller of [`crate::Publisher::publish_with()`], and they
27    /// have precedence over the fallback options.
28    ///
29    /// > Note: Only the option fields explicitly overriden should be written,
30    /// > letting all other fields to `None`.
31    ///
32    fn publish_overrides(&self) -> PublishOptions;
33}