Skip to main content

Listener

Struct Listener 

Source
pub struct Listener { /* private fields */ }
Expand description

Listener attached to a Participant.

In the DDS entity hierarchy this composes SubscriberListener, PublisherListener, and TopicListener. When attached to a participant, entities created under it inherit any of the configured callbacks that apply to that entity type.

§Examples

use cyclonedds::{Domain, Listener, Participant, Subscriber};

let domain = Domain::default();
let listener = Listener::new().with_subscriber(|subscriber_listener| {
    subscriber_listener
        .with_data_on_readers(|subscriber| println!("{subscriber:?} has data on readers"))
});
let participant = Participant::builder(&domain)
    .with_listener(&listener)
    .build()?;

// This subscriber inherits the callbacks set on the `participant` via the `listener`.
let subscriber = Subscriber::new(&participant)?;

// This subscriber will have the subscriber subset associated with the `listener` directly
// applied to it.
let subscriber = Subscriber::builder(&participant)
    .with_listener(&listener)
    .build()?;

Implementations§

Source§

impl Listener

Source

pub fn new() -> Self

Creates a new Listener with no callbacks registered.

§Examples
use cyclonedds::Listener;

let listener = Listener::new();
Source

pub fn with_subscriber( self, setter: fn(SubscriberListener) -> SubscriberListener, ) -> Self

Configures the SubscriberListener via a setter callback.

§Examples
use cyclonedds::Listener;

let listener = Listener::new().with_subscriber(|s| {
    s.with_data_on_readers(|subscriber| {
        println!("data available on a reader");
    })
});
Source

pub fn with_publisher( self, setter: fn(PublisherListener) -> PublisherListener, ) -> Self

Configures the PublisherListener via a setter callback.

§Examples

This example does not compile because the PublisherListener does not have its with_writer::<T> setter yet. This is due to the fact that the higher-level listeners are untyped in <T> but the lower-level listeners are typed in <T> and a solution for crossing this boundary still needs to be worked out.

See the module-level warning for more detail.

use cyclonedds::Listener;

let listener = Listener::new().with_publisher(|p| {
    p.with_writer(|w| {
        w.with_publication_matched(|writer, publication_matched| {
            println!("{writer:?} has publication match: {publication_matched:?}")
        })
    })
});

Trait Implementations§

Source§

impl AsRef<Listener> for Listener

Source§

fn as_ref(&self) -> &Listener

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl AsRef<PublisherListener> for Listener

Source§

fn as_ref(&self) -> &PublisherListener

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl AsRef<SubscriberListener> for Listener

Source§

fn as_ref(&self) -> &SubscriberListener

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Clone for Listener

Source§

fn clone(&self) -> Listener

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Listener

Source§

impl Debug for Listener

Source§

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

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

impl Default for Listener

Source§

fn default() -> Listener

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.