Struct Publisher

Source
pub struct Publisher<Service: Service, Payload: Debug + ZeroCopySend + ?Sized + 'static, UserHeader: Debug + ZeroCopySend> { /* private fields */ }
Expand description

Sending endpoint of a publish-subscriber based communication.

Implementations§

Source§

impl<Service: Service, Payload: Debug + ZeroCopySend + ?Sized, UserHeader: Debug + ZeroCopySend> Publisher<Service, Payload, UserHeader>

Source

pub fn id(&self) -> UniquePublisherId

Returns the UniquePublisherId of the Publisher

Source

pub fn unable_to_deliver_strategy(&self) -> UnableToDeliverStrategy

Returns the strategy the Publisher follows when a SampleMut cannot be delivered since the Subscribers buffer is full.

Source§

impl<Service: Service, Payload: Debug + ZeroCopySend + Sized, UserHeader: Debug + ZeroCopySend> Publisher<Service, Payload, UserHeader>

Source

pub fn send_copy(&self, value: Payload) -> Result<usize, SendError>

Copies the input value into a crate::sample_mut::SampleMut and delivers it. On success it returns the number of crate::port::subscriber::Subscribers that received the data, otherwise a SendError describing the failure.

§Example
use iceoryx2::prelude::*;
                         .create()?;

publisher.send_copy(1234)?;
Source

pub fn loan_uninit( &self, ) -> Result<SampleMutUninit<Service, MaybeUninit<Payload>, UserHeader>, LoanError>

Loans/allocates a SampleMutUninit from the underlying data segment of the Publisher. The user has to initialize the payload before it can be sent.

On failure it returns LoanError describing the failure.

§Example
use iceoryx2::prelude::*;
                         .create()?;

let sample = publisher.loan_uninit()?;
let sample = sample.write_payload(42); // alternatively `sample.payload_mut()` can be use to access the `MaybeUninit<Payload>`

sample.send()?;
Source§

impl<Service: Service, Payload: Default + Debug + ZeroCopySend + Sized, UserHeader: Debug + ZeroCopySend> Publisher<Service, Payload, UserHeader>

Source

pub fn loan(&self) -> Result<SampleMut<Service, Payload, UserHeader>, LoanError>

Loans/allocates a crate::sample_mut::SampleMut from the underlying data segment of the Publisher and initialize it with the default value. This can be a performance hit and Publisher::loan_uninit can be used to loan a core::mem::MaybeUninit<Payload>.

On failure it returns LoanError describing the failure.

§Example
use iceoryx2::prelude::*;

let mut sample = publisher.loan()?;
*sample.payload_mut() = 42;

sample.send()?;
Source§

impl<Service: Service, Payload: Default + Debug + ZeroCopySend, UserHeader: Debug + ZeroCopySend> Publisher<Service, [Payload], UserHeader>

Source

pub fn loan_slice( &self, number_of_elements: usize, ) -> Result<SampleMut<Service, [Payload], UserHeader>, LoanError>

Loans/allocates a crate::sample_mut::SampleMut from the underlying data segment of the Publisher and initializes all slice elements with the default value. This can be a performance hit and Publisher::loan_slice_uninit() can be used to loan a slice of core::mem::MaybeUninit<Payload>.

On failure it returns LoanError describing the failure.

§Example
use iceoryx2::prelude::*;
                         .initial_max_slice_len(120)
                         .create()?;

let slice_length = 5;
let mut sample = publisher.loan_slice(slice_length)?;
sample.payload_mut()[2] = 42;

sample.send()?;
Source§

impl<Service: Service, Payload: Debug + ZeroCopySend, UserHeader: Debug + ZeroCopySend> Publisher<Service, [Payload], UserHeader>

Source

pub fn initial_max_slice_len(&self) -> usize

Returns the maximum initial slice length configured for this Publisher.

Source

pub fn loan_slice_uninit( &self, slice_len: usize, ) -> Result<SampleMutUninit<Service, [MaybeUninit<Payload>], UserHeader>, LoanError>

Loans/allocates a SampleMutUninit from the underlying data segment of the Publisher. The user has to initialize the payload before it can be sent.

On failure it returns LoanError describing the failure.

§Example
use iceoryx2::prelude::*;

                         .initial_max_slice_len(120)
                         .create()?;

let slice_length = 5;
let sample = publisher.loan_slice_uninit(slice_length)?;
let sample = sample.write_from_fn(|n| n * 2); // alternatively `sample.payload_mut()` can be use to access the `[MaybeUninit<Payload>]`

sample.send()?;

Trait Implementations§

Source§

impl<Service: Debug + Service, Payload: Debug + Debug + ZeroCopySend + ?Sized + 'static, UserHeader: Debug + Debug + ZeroCopySend> Debug for Publisher<Service, Payload, UserHeader>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<Service: Service, Payload: Debug + ZeroCopySend + ?Sized, UserHeader: Debug + ZeroCopySend> Drop for Publisher<Service, Payload, UserHeader>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<Service: Service, Payload: Debug + ZeroCopySend + ?Sized, UserHeader: Debug + ZeroCopySend> UpdateConnections for Publisher<Service, Payload, UserHeader>

Source§

fn update_connections(&self) -> Result<(), ConnectionFailure>

Explicitly updates all connections to the crate::port::subscriber::Subscribers. This is required to be called whenever a new crate::port::subscriber::Subscriber connected to the service. It is done implicitly whenever crate::sample_mut::SampleMut::send() or crate::port::publisher::Publisher::send_copy() is called. When a crate::port::subscriber::Subscriber is connected that requires a history this call will deliver it. Read more

Auto Trait Implementations§

§

impl<Service, Payload, UserHeader> Freeze for Publisher<Service, Payload, UserHeader>
where Payload: ?Sized,

§

impl<Service, Payload, UserHeader> !RefUnwindSafe for Publisher<Service, Payload, UserHeader>

§

impl<Service, Payload, UserHeader> !Send for Publisher<Service, Payload, UserHeader>

§

impl<Service, Payload, UserHeader> !Sync for Publisher<Service, Payload, UserHeader>

§

impl<Service, Payload, UserHeader> Unpin for Publisher<Service, Payload, UserHeader>
where Payload: Unpin + ?Sized, UserHeader: Unpin,

§

impl<Service, Payload, UserHeader> !UnwindSafe for Publisher<Service, Payload, UserHeader>

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.