pub trait Publisher: Send + Sync {
// Required methods
fn prepare(
&self,
len: usize
) -> Result<Box<dyn PublishSample<'_> + '_>, Box<dyn Error + Send + Sync + 'static>>;
fn dyn_clone(&self) -> Box<dyn Publisher>;
// Provided method
fn publish(
&self,
data: &[u8]
) -> Result<(), Box<dyn Error + Send + Sync + 'static>> { ... }
}
Expand description
Allows publishing messages to subscribers.
The messages is published to the topic that was used to create the publisher
(see CommunicationLayer::publisher
).
Required Methods§
sourcefn prepare(
&self,
len: usize
) -> Result<Box<dyn PublishSample<'_> + '_>, Box<dyn Error + Send + Sync + 'static>>
fn prepare( &self, len: usize ) -> Result<Box<dyn PublishSample<'_> + '_>, Box<dyn Error + Send + Sync + 'static>>
Prepare memory for publishing a message with the given length.
This function makes it possible to construct messages without
any additional copying. The returned [Sample
] is initialized
with zeros.
sourcefn dyn_clone(&self) -> Box<dyn Publisher>
fn dyn_clone(&self) -> Box<dyn Publisher>
Clone this publisher, returning the clone as a trait object.
Provided Methods§
sourcefn publish(
&self,
data: &[u8]
) -> Result<(), Box<dyn Error + Send + Sync + 'static>>
fn publish( &self, data: &[u8] ) -> Result<(), Box<dyn Error + Send + Sync + 'static>>
Publishes the gives message to subscribers.
Depending on the backend, this method might need to copy the data, which can
decrease performance. To avoid this, the prepare
function
can be used to construct the message in-place.