pub struct Publisher<T: Debug + ZeroCopySend + 'static> { /* private fields */ }Expand description
Pub/sub publisher that auto-notifies the paired event service on every send.
Implementations§
Source§impl<T: Payload + Copy> Publisher<T>
impl<T: Payload + Copy> Publisher<T>
Sourcepub fn send_copy(&self, value: T) -> Result<NotifyOutcome, ExecutorError>
pub fn send_copy(&self, value: T) -> Result<NotifyOutcome, ExecutorError>
Send by value (copies). Notifies the paired event service on success.
Returns a NotifyOutcome whose listeners_notified field reports how
many listeners actually received the wakeup. A value less than the
number of attached subscribers means at least one listener’s kernel
socket buffer was full at notification time (the data is still
delivered — only the wakeup signal was dropped). See NotifyOutcome
for guidance on interpreting this value.
Source§impl<T: Payload> Publisher<T>
impl<T: Payload> Publisher<T>
Sourcepub fn loan_send<F>(&self, f: F) -> Result<NotifyOutcome, ExecutorError>
pub fn loan_send<F>(&self, f: F) -> Result<NotifyOutcome, ExecutorError>
§Example
use iceoryx2::prelude::*;
use taktora_executor::Channel;
use std::sync::Arc;
#[derive(Debug, Default, Clone, Copy, ZeroCopySend)]
#[repr(C)]
struct Tick(u64);
let node = NodeBuilder::new().create::<ipc::Service>()?;
let ch: Arc<Channel<Tick>> = Channel::open_or_create(&node, "demo")?;
let publisher = ch.publisher()?;
let _ = publisher.loan_send(|t: &mut Tick| { t.0 = 1; true })?;Loan a sample initialised to T::default(), run f to fill it, then
send + notify. Returns a NotifyOutcome with sent == false if f
returns false — caller signalled “skip send”.
When sent == true, listeners_notified reports how many listeners
received the wakeup. A value less than the number of attached subscribers
means at least one listener’s kernel socket buffer was full (dropped
wakeup — data is still delivered). See NotifyOutcome for details.
T: Default is required here because the shared-memory slot is
pre-initialised via T::default() before the closure runs. For types
that do not implement Default, use loan instead.
Sourcepub fn loan<F>(&self, f: F) -> Result<NotifyOutcome, ExecutorError>
pub fn loan<F>(&self, f: F) -> Result<NotifyOutcome, ExecutorError>
True zero-copy send. The closure receives &mut MaybeUninit<T>; it
must fully initialize the payload (e.g., via MaybeUninit::write(v)
or in-place construction such as iceoryx2’s placement_default!)
before returning true. Returning false skips the send.
On success, sends and notifies. Returns a NotifyOutcome with
sent == true if the payload was sent, sent == false if the closure
returned false. When sent == true, listeners_notified reports how
many listeners received the wakeup — see NotifyOutcome for details.
§Contract
Returning true from the closure asserts that the payload is
fully initialized. Returning true without writing a valid T
causes undefined behaviour at the subsequent assume_init step.
T: Default is not required — that’s the point of this method
versus loan_send. For types that have a sensible
Default and are cheap to default-construct, prefer loan_send.
§Example
use core::mem::MaybeUninit;
use iceoryx2::prelude::*;
use taktora_executor::Channel;
use std::sync::Arc;
#[derive(Debug, ZeroCopySend)]
#[repr(C)]
struct LargeMsg { payload: [u8; 64] }
// Manual Default impl — e.g. initialised to a sentinel value rather
// than zero, so `loan_send` would use it but it is expensive.
impl Default for LargeMsg {
fn default() -> Self { LargeMsg { payload: [0xFF; 64] } }
}
let node = NodeBuilder::new().create::<ipc::Service>()?;
let ch: Arc<Channel<LargeMsg>> = Channel::open_or_create(&node, "demo")?;
let publisher = ch.publisher()?;
let _ = publisher.loan(|slot: &mut MaybeUninit<LargeMsg>| {
// Initialise directly in shared memory — no Default construction,
// no stack temporary for the payload array.
slot.write(LargeMsg { payload: [0u8; 64] });
true
})?;