pub trait TopicWriter<T>: Send + Sync {
// Required method
fn write_topic(
&self,
value: &T,
out: &mut TopicBuf<'_>,
) -> Result<bool, TopicOverflow>;
}Expand description
Writes an outbound link’s destination for each value (outbound only).
Closures implement it, and with_topic_fn
takes one directly. A writer type goes to
with_topic_writer.
§Example
use aimdb_core::connector::{TopicBuf, TopicOverflow, TopicWriter};
use core::fmt::Write;
struct SensorTopic;
impl TopicWriter<Temperature> for SensorTopic {
fn write_topic(&self, value: &Temperature, out: &mut TopicBuf<'_>) -> Result<bool, TopicOverflow> {
write!(out, "sensors/temp/{}", value.sensor_id)?;
Ok(true)
}
}Required Methods§
Sourcefn write_topic(
&self,
value: &T,
out: &mut TopicBuf<'_>,
) -> Result<bool, TopicOverflow>
fn write_topic( &self, value: &T, out: &mut TopicBuf<'_>, ) -> Result<bool, TopicOverflow>
Write the destination for value into out.
Ok(true) publishes to what was written, Ok(false) to the static
topic from the link_to() URL. A value whose topic does not fit is
skipped, whatever this returns; the topic is never truncated.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".