Skip to main content

Topic

Struct Topic 

Source
pub struct Topic<'domain, 'participant, T>
where T: Topicable,
{ /* private fields */ }
Expand description

A typed communication channel.

A Topic binds a name to a data type T within a Participant. Writers and Readers are created against a topic and only match each other when they share the same topic name and compatible type and QoS.

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

Implementations§

Source§

impl<'d, 'p, T> Topic<'d, 'p, T>
where T: Topicable,

Source

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

Creates a new Topic with the given name under participant using default QoS and no listener.

The topic name identifies the communication channel. Writers and readers match when they share the same name and compatible type.

§Errors

Returns an Error if topic fails to create.

§Examples
use cyclonedds::Topic;

let topic = Topic::<Data>::new(&participant, "MyTopic")?;
Source

pub const fn builder<'q, 'n>( participant: &'p Participant<'d>, topic_name: &'n str, ) -> TopicBuilder<'d, 'p, 'q, 'n, T>

Returns a TopicBuilder for constructing a topic with custom QoS or a listener.

§Examples
use cyclonedds::Topic;

let topic = Topic::<Data>::builder(&participant, "MyTopic").build()?;
Source

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

Sets the TopicListener on this topic, replacing any previously set listener.

§Errors

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

§Examples
use cyclonedds::listener::TopicListener;

let mut topic = Topic::<Data>::new(&participant, "MyTopic")?;
topic.set_listener(TopicListener::new().with_inconsistent_topic(|_, status| {
    println!("inconsistent topic: {status:?}");
}))?;
Source

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

Removes the listener from this topic.

§Errors

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

§Examples
let mut topic = Topic::<Data>::new(&participant, "MyTopic")?;
topic.unset_listener()?;
Source

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

Sets the TopicListener on this topic, consuming and returning self.

§Errors

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

§Examples
use cyclonedds::listener::TopicListener;

let topic = Topic::<Data>::new(&participant, "MyTopic")?.with_listener(TopicListener::new())?;

Trait Implementations§

Source§

impl<'domain, 'participant, T> Debug for Topic<'domain, 'participant, T>
where T: Topicable + Debug,

Source§

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

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

impl<T> Drop for Topic<'_, '_, T>
where T: Topicable,

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<T: Topicable> Entity for Topic<'_, '_, T>

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, T> Freeze for Topic<'domain, 'participant, T>

§

impl<'domain, 'participant, T> RefUnwindSafe for Topic<'domain, 'participant, T>
where T: RefUnwindSafe,

§

impl<'domain, 'participant, T> Send for Topic<'domain, 'participant, T>
where T: Send,

§

impl<'domain, 'participant, T> Sync for Topic<'domain, 'participant, T>
where T: Sync,

§

impl<'domain, 'participant, T> Unpin for Topic<'domain, 'participant, T>
where T: Unpin,

§

impl<'domain, 'participant, T> UnsafeUnpin for Topic<'domain, 'participant, T>

§

impl<'domain, 'participant, T> UnwindSafe for Topic<'domain, 'participant, T>
where T: UnwindSafe,

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.