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>
impl<Service: Service, Payload: Debug + ZeroCopySend + ?Sized, UserHeader: Debug + ZeroCopySend> Publisher<Service, Payload, UserHeader>
Sourcepub fn id(&self) -> UniquePublisherId
pub fn id(&self) -> UniquePublisherId
Returns the UniquePublisherId
of the Publisher
Sourcepub fn unable_to_deliver_strategy(&self) -> UnableToDeliverStrategy
pub fn unable_to_deliver_strategy(&self) -> UnableToDeliverStrategy
Returns the strategy the Publisher
follows when a SampleMut
cannot be delivered
since the Subscriber
s buffer is full.
Source§impl<Service: Service, Payload: Debug + ZeroCopySend + Sized, UserHeader: Debug + ZeroCopySend> Publisher<Service, Payload, UserHeader>
impl<Service: Service, Payload: Debug + ZeroCopySend + Sized, UserHeader: Debug + ZeroCopySend> Publisher<Service, Payload, UserHeader>
Sourcepub fn send_copy(&self, value: Payload) -> Result<usize, SendError>
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::Subscriber
s that received
the data, otherwise a SendError
describing the failure.
§Example
use iceoryx2::prelude::*;
.create()?;
publisher.send_copy(1234)?;
Sourcepub fn loan_uninit(
&self,
) -> Result<SampleMutUninit<Service, MaybeUninit<Payload>, UserHeader>, LoanError>
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>
impl<Service: Service, Payload: Default + Debug + ZeroCopySend + Sized, UserHeader: Debug + ZeroCopySend> Publisher<Service, Payload, UserHeader>
Sourcepub fn loan(&self) -> Result<SampleMut<Service, Payload, UserHeader>, LoanError>
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>
impl<Service: Service, Payload: Default + Debug + ZeroCopySend, UserHeader: Debug + ZeroCopySend> Publisher<Service, [Payload], UserHeader>
Sourcepub fn loan_slice(
&self,
number_of_elements: usize,
) -> Result<SampleMut<Service, [Payload], UserHeader>, LoanError>
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>
impl<Service: Service, Payload: Debug + ZeroCopySend, UserHeader: Debug + ZeroCopySend> Publisher<Service, [Payload], UserHeader>
Sourcepub fn initial_max_slice_len(&self) -> usize
pub fn initial_max_slice_len(&self) -> usize
Returns the maximum initial slice length configured for this Publisher
.
Sourcepub fn loan_slice_uninit(
&self,
slice_len: usize,
) -> Result<SampleMutUninit<Service, [MaybeUninit<Payload>], UserHeader>, LoanError>
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>
impl<Service: Debug + Service, Payload: Debug + Debug + ZeroCopySend + ?Sized + 'static, UserHeader: Debug + Debug + ZeroCopySend> Debug for Publisher<Service, Payload, UserHeader>
Source§impl<Service: Service, Payload: Debug + ZeroCopySend + ?Sized, UserHeader: Debug + ZeroCopySend> Drop for Publisher<Service, Payload, UserHeader>
impl<Service: Service, Payload: Debug + ZeroCopySend + ?Sized, UserHeader: Debug + ZeroCopySend> Drop for Publisher<Service, Payload, UserHeader>
Source§impl<Service: Service, Payload: Debug + ZeroCopySend + ?Sized, UserHeader: Debug + ZeroCopySend> UpdateConnections for Publisher<Service, Payload, UserHeader>
impl<Service: Service, Payload: Debug + ZeroCopySend + ?Sized, UserHeader: Debug + ZeroCopySend> UpdateConnections for Publisher<Service, Payload, UserHeader>
Source§fn update_connections(&self) -> Result<(), ConnectionFailure>
fn update_connections(&self) -> Result<(), ConnectionFailure>
crate::port::subscriber::Subscriber
s. 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