Skip to main content

Subscriber

Struct Subscriber 

Source
pub struct Subscriber<'domain, 'participant> { /* private fields */ }
Expand description

A Subscriber groups Readers and controls their shared QoS. Readers created under a subscriber inherit its QoS where applicable.

Use Subscriber::new for simple construction or Subscriber::builder for QoS and listener configuration.

In most applications a subscriber is created implicitly when constructing a Reader directly. Use an explicit subscriber when you need coordinated reads across multiple readers.

Implementations§

Source§

impl<'d, 'p> Subscriber<'d, 'p>

Source

pub fn new(participant: &'p Participant<'d>) -> Result<Self>

Creates a new Subscriber under participant with default QoS and no listener.

§Errors

Returns an Error if the subscriber fails to create.

§Examples
use cyclonedds::Subscriber;

let subscriber = Subscriber::new(&participant)?;
Ok::<_, cyclonedds::Error>(())
Source

pub const fn builder<'q>( participant: &'p Participant<'d>, ) -> SubscriberBuilder<'d, 'p, 'q>

Returns a SubscriberBuilder for constructing a subscriber with custom QoS or a listener.

§Examples
use cyclonedds::{
    QoS, Subscriber,
    qos::policy::{Durability, Presentation},
};

let qos = QoS::new().with_presentation(Presentation::Topic {
    coherent_access: true,
    ordered_access: true,
});
let subscriber = Subscriber::builder(&participant).with_qos(&qos).build()?;
Ok::<_, cyclonedds::Error>(())
Source

pub fn notify_readers(&self) -> Result<()>

(WARN: unimplemented in C lib): Notifies all readers belonging to this subscriber that data is available.

This function is currently not implemented by the underlying C library and will thus always return an unsupported error.

Triggers the DataOnReaders callback on the subscriber’s listener and the DataAvailable callback on each reader’s listener.

§Errors

Returns an Error if the subscriber fails to notify the readers.

§Examples
use cyclonedds::Subscriber;

let subscriber = Subscriber::new(&participant)?;
subscriber.notify_readers()?;
Source

pub fn set_listener<L>(&mut self, listener: L) -> Result<()>

Sets the SubscriberListener on this subscriber, replacing any previously set listener.

§Errors

Returns an Error if the subscriber fails to set the listener.

§Examples
use cyclonedds::SubscriberListener;

let mut subscriber = Subscriber::new(&participant)?;
subscriber.set_listener(SubscriberListener::new())?;
Source

pub fn unset_listener(&mut self) -> Result<()>

Removes the listener from this subscriber.

§Errors

Returns an Error if the subscriber fails to unset the listener.

§Examples
let mut subscriber = Subscriber::new(&participant)?;
subscriber.unset_listener()?;
Source

pub fn with_listener<L>(self, listener: L) -> Result<Self>

Sets the SubscriberListener on this subscriber, consuming and returning self.

§Errors

Returns an Error if the subscriber fails to set the listener.

§Examples
use cyclonedds::SubscriberListener;

let subscriber = Subscriber::new(&participant)?.with_listener(SubscriberListener::new())?;

Trait Implementations§

Source§

impl<'domain, 'participant> Debug for Subscriber<'domain, 'participant>

Source§

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

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

impl Drop for Subscriber<'_, '_>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl Entity for Subscriber<'_, '_>

Source§

fn id(&self) -> EntityId

Returns the EntityId of this entity. Read more
Source§

fn instance_handle(&self) -> Result<InstanceHandle>

Returns the InstanceHandle of this entity. Read more
Source§

fn status_changes(&self) -> Result<Status>

Returns the set of status flags that have changed since they were last read or taken. Read more
Source§

fn take_status(&self, mask: Option<Status>) -> Result<Status>

Takes and clears the status flags matching mask, or all flags if mask is None. Read more
Source§

fn read_status(&self, mask: Option<Status>) -> Result<Status>

Reads the status flags matching mask without clearing them, or all flags if mask is None. Read more
Source§

fn status_mask(&self) -> Result<Status>

Returns the status mask enabled on the entity. Read more
Source§

fn set_status_mask(&self, mask: Status) -> Result<()>

Sets and enables a status mask on the entity. Read more

Auto Trait Implementations§

§

impl<'domain, 'participant> Freeze for Subscriber<'domain, 'participant>

§

impl<'domain, 'participant> RefUnwindSafe for Subscriber<'domain, 'participant>

§

impl<'domain, 'participant> Send for Subscriber<'domain, 'participant>

§

impl<'domain, 'participant> Sync for Subscriber<'domain, 'participant>

§

impl<'domain, 'participant> Unpin for Subscriber<'domain, 'participant>

§

impl<'domain, 'participant> UnsafeUnpin for Subscriber<'domain, 'participant>

§

impl<'domain, 'participant> UnwindSafe for Subscriber<'domain, 'participant>

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> Same for T

Source§

type Output = T

Should always be Self
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.