Skip to main content

Publisher

Struct Publisher 

Source
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>

Source

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>

Source

pub fn loan_send<F>(&self, f: F) -> Result<NotifyOutcome, ExecutorError>
where T: Default, F: FnOnce(&mut T) -> bool,

§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.

Source

pub fn loan<F>(&self, f: F) -> Result<NotifyOutcome, ExecutorError>
where F: FnOnce(&mut MaybeUninit<T>) -> bool,

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
})?;

Trait Implementations§

Source§

impl<T: Debug + ZeroCopySend + 'static> Send for Publisher<T>

Auto Trait Implementations§

§

impl<T> Freeze for Publisher<T>

§

impl<T> !RefUnwindSafe for Publisher<T>

§

impl<T> !Sync for Publisher<T>

§

impl<T> Unpin for Publisher<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for Publisher<T>

§

impl<T> !UnwindSafe for Publisher<T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.