pub struct Publisher { /* private fields */ }
Expand description
DDS Publisher
The Publisher and Subscriber structures are collections of DataWriters and, respectively, DataReaders. They can contain DataWriters or DataReaders of different types, and attacehd to different Topics.
They can act as a domain of sample ordering or atomicity, if such QoS policies are used. For example, DDS participants could agree via QoS policies that data samples must be presented to readers in the same order as writers have written them, and the ordering applies also between several writers/readers, but within one publisher/subscriber. Analogous arrangement can be set up w.r.t. coherency: All the samples in a transaction are delivered to the readers, or none are. The transaction can span several readers, writers, and topics in a single publisher/subscriber.
Examples
use rustdds::dds::Publisher;
let domain_participant = DomainParticipant::new(0).unwrap();
let qos = QosPolicyBuilder::new().build();
let publisher = domain_participant.create_publisher(&qos);
Implementations
sourceimpl Publisher
impl Publisher
sourcepub fn create_datawriter<D, SA>(
&self,
topic: &Topic,
qos: Option<QosPolicies>
) -> Result<WithKeyDataWriter<D, SA>> where
D: Keyed + Serialize,
<D as Keyed>::K: Key,
SA: SerializerAdapter<D>,
pub fn create_datawriter<D, SA>(
&self,
topic: &Topic,
qos: Option<QosPolicies>
) -> Result<WithKeyDataWriter<D, SA>> where
D: Keyed + Serialize,
<D as Keyed>::K: Key,
SA: SerializerAdapter<D>,
Creates DDS DataWriter for Keyed topic
Arguments
entity_id
- Custom entity id if necessary for the user to define ittopic
- Reference to DDS Topic this writer is created toqos
- Not currently in use
Examples
use rustdds::dds::traits::Keyed;
use rustdds::serialization::CDRSerializerAdapter;
use serde::Serialize;
let domain_participant = DomainParticipant::new(0).unwrap();
let qos = QosPolicyBuilder::new().build();
let publisher = domain_participant.create_publisher(&qos).unwrap();
#[derive(Serialize)]
struct SomeType { a: i32 }
impl Keyed for SomeType {
type K = i32;
fn key(&self) -> Self::K {
self.a
}
}
let topic = domain_participant.create_topic("some_topic".to_string(), "SomeType".to_string(), &qos, TopicKind::WithKey).unwrap();
let data_writer = publisher.create_datawriter::<SomeType, CDRSerializerAdapter<_>>(&topic, None);
sourcepub fn create_datawriter_cdr<D>(
&self,
topic: &Topic,
qos: Option<QosPolicies>
) -> Result<WithKeyDataWriter<D, CDRSerializerAdapter<D, LittleEndian>>> where
D: Keyed + Serialize,
<D as Keyed>::K: Key,
pub fn create_datawriter_cdr<D>(
&self,
topic: &Topic,
qos: Option<QosPolicies>
) -> Result<WithKeyDataWriter<D, CDRSerializerAdapter<D, LittleEndian>>> where
D: Keyed + Serialize,
<D as Keyed>::K: Key,
Shorthand for crate_datawriter with Commaon Data Representation Little Endian
sourcepub fn create_datawriter_no_key<D, SA>(
&self,
topic: &Topic,
qos: Option<QosPolicies>
) -> Result<NoKeyDataWriter<D, SA>> where
D: Serialize,
SA: SerializerAdapter<D>,
pub fn create_datawriter_no_key<D, SA>(
&self,
topic: &Topic,
qos: Option<QosPolicies>
) -> Result<NoKeyDataWriter<D, SA>> where
D: Serialize,
SA: SerializerAdapter<D>,
Creates DDS DataWriter for Nokey Topic
Arguments
entity_id
- Custom entity id if necessary for the user to define ittopic
- Reference to DDS Topic this writer is created toqos
- QoS policies for this DataWriter
Examples
use rustdds::serialization::CDRSerializerAdapter;
use serde::Serialize;
let domain_participant = DomainParticipant::new(0).unwrap();
let qos = QosPolicyBuilder::new().build();
let publisher = domain_participant.create_publisher(&qos).unwrap();
#[derive(Serialize)]
struct SomeType {}
let topic = domain_participant.create_topic("some_topic".to_string(), "SomeType".to_string(), &qos, TopicKind::WithKey).unwrap();
let data_writer = publisher.create_datawriter_no_key::<SomeType, CDRSerializerAdapter<_>>(&topic, None);
pub fn create_datawriter_no_key_cdr<D>(
&self,
topic: &Topic,
qos: Option<QosPolicies>
) -> Result<NoKeyDataWriter<D, CDRSerializerAdapter<D, LittleEndian>>> where
D: Serialize,
sourcepub fn suspend_publications(&self) -> Result<()>
pub fn suspend_publications(&self) -> Result<()>
Currently does nothing
sourcepub fn resume_publications(&self) -> Result<()>
pub fn resume_publications(&self) -> Result<()>
Currently does nothing
sourcepub fn begin_coherent_changes(&self) -> Result<()>
pub fn begin_coherent_changes(&self) -> Result<()>
Coherent set not implemented and currently does nothing
sourcepub fn end_coherent_changes(&self) -> Result<()>
pub fn end_coherent_changes(&self) -> Result<()>
Coherent set not implemented and currently does nothing
sourcepub fn wait_for_acknowledgments(&self, max_wait: Duration) -> Result<()>
pub fn wait_for_acknowledgments(&self, max_wait: Duration) -> Result<()>
Wait for all matched reliable DataReaders acknowledge data written so far, or timeout. /Not implemeted/
sourcepub fn participant(&self) -> Option<DomainParticipant>
pub fn participant(&self) -> Option<DomainParticipant>
Gets DomainParticipant if it has not disappeared from all scopes.
Example
let domain_participant = DomainParticipant::new(0).unwrap();
let qos = QosPolicyBuilder::new().build();
let publisher = domain_participant.create_publisher(&qos).unwrap();
assert_eq!(domain_participant, publisher.participant().unwrap());
sourcepub fn get_default_datawriter_qos(&self) -> QosPolicies
pub fn get_default_datawriter_qos(&self) -> QosPolicies
Returns default DataWriter qos.
Example
use rustdds::dds::qos::{QosPolicyBuilder};
let domain_participant = DomainParticipant::new(0).unwrap();
let qos = QosPolicyBuilder::new().build();
let publisher = domain_participant.create_publisher(&qos).unwrap();
assert_eq!(qos, publisher.get_default_datawriter_qos());
sourcepub fn set_default_datawriter_qos(&mut self, q: &QosPolicies)
pub fn set_default_datawriter_qos(&mut self, q: &QosPolicies)
Sets default DataWriter qos.
Example
let domain_participant = DomainParticipant::new(0).unwrap();
let qos = QosPolicyBuilder::new().build();
let mut publisher = domain_participant.create_publisher(&qos).unwrap();
let qos2 =
QosPolicyBuilder::new().durability(Durability::Transient).build();
publisher.set_default_datawriter_qos(&qos2);
assert_ne!(qos, publisher.get_default_datawriter_qos());
assert_eq!(qos2, publisher.get_default_datawriter_qos());
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Publisher
impl Send for Publisher
impl Sync for Publisher
impl Unpin for Publisher
impl UnwindSafe for Publisher
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more