Struct rustdds::dds::with_key::DataWriter
source · pub struct DataWriter<D: Keyed, SA: SerializerAdapter<D> = CDRSerializerAdapter<D>> { /* private fields */ }
Expand description
DDS DataWriter for keyed topics
§Examples
use serde::{Serialize, Deserialize};
use rustdds::*;
use rustdds::with_key::DataWriter;
use rustdds::serialization::CDRSerializerAdapter;
let domain_participant = DomainParticipant::new(0).unwrap();
let qos = QosPolicyBuilder::new().build();
let publisher = domain_participant.create_publisher(&qos).unwrap();
#[derive(Serialize, Deserialize, Debug)]
struct SomeType { a: i32 }
impl Keyed for SomeType {
type K = i32;
fn key(&self) -> Self::K {
self.a
}
}
// WithKey is important
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);
Implementations§
source§impl<D, SA> DataWriter<D, SA>where
D: Keyed,
SA: SerializerAdapter<D>,
impl<D, SA> DataWriter<D, SA>where
D: Keyed,
SA: SerializerAdapter<D>,
sourcepub fn refresh_manual_liveliness(&self)
pub fn refresh_manual_liveliness(&self)
Manually refreshes liveliness if QoS allows it
§Examples
let domain_participant = DomainParticipant::new(0).unwrap();
let qos = QosPolicyBuilder::new().build();
let publisher = domain_participant.create_publisher(&qos).unwrap();
#[derive(Serialize, Deserialize, Debug)]
struct SomeType { a: i32 }
impl Keyed for SomeType {
type K = i32;
fn key(&self) -> Self::K {
self.a
}
}
// WithKey is important
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).unwrap();
data_writer.refresh_manual_liveliness();
sourcepub fn write(
&self,
data: D,
source_timestamp: Option<Timestamp>
) -> WriteResult<(), D>
pub fn write( &self, data: D, source_timestamp: Option<Timestamp> ) -> WriteResult<(), D>
Writes single data instance to a topic.
§Examples
let domain_participant = DomainParticipant::new(0).unwrap();
let qos = QosPolicyBuilder::new().build();
let publisher = domain_participant.create_publisher(&qos).unwrap();
#[derive(Serialize, Deserialize, Debug)]
struct SomeType { a: i32 }
impl Keyed for SomeType {
type K = i32;
fn key(&self) -> Self::K {
self.a
}
}
// WithKey is important
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).unwrap();
let some_data = SomeType { a: 1 };
data_writer.write(some_data, None).unwrap();
pub fn write_with_options( &self, data: D, write_options: WriteOptions ) -> WriteResult<SampleIdentity, D>
sourcepub fn wait_for_acknowledgments(
&self,
max_wait: Duration
) -> WriteResult<bool, ()>
pub fn wait_for_acknowledgments( &self, max_wait: Duration ) -> WriteResult<bool, ()>
This operation blocks the calling thread until either all data written by
the reliable DataWriter entities is acknowledged by all
matched reliable DataReader entities, or else the duration specified by
the max_wait
parameter elapses, whichever happens first.
See DDS Spec 1.4 Section 2.2.2.4.1.12 wait_for_acknowledgments.
If this DataWriter is not set to Reliable, or there are no matched DataReaders with Reliable QoS, the call succeeds immediately.
Return values
Ok(true)
- all acknowledgedOk(false)
- timed out waiting for acknowledgmentsErr(_)
- something went wrong
§Examples
let domain_participant = DomainParticipant::new(0).unwrap();
let qos = QosPolicyBuilder::new().build();
let publisher = domain_participant.create_publisher(&qos).unwrap();
#[derive(Serialize, Deserialize, Debug)]
struct SomeType { a: i32 }
impl Keyed for SomeType {
type K = i32;
fn key(&self) -> Self::K {
self.a
}
}
// WithKey is important
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).unwrap();
let some_data = SomeType { a: 1 };
data_writer.write(some_data, None).unwrap();
data_writer.wait_for_acknowledgments(std::time::Duration::from_millis(100));
sourcepub fn topic(&self) -> &Topic
pub fn topic(&self) -> &Topic
Topic assigned to this DataWriter
§Examples
let domain_participant = DomainParticipant::new(0).unwrap();
let qos = QosPolicyBuilder::new().build();
let publisher = domain_participant.create_publisher(&qos).unwrap();
#[derive(Serialize, Deserialize, Debug)]
struct SomeType { a: i32 }
impl Keyed for SomeType {
type K = i32;
fn key(&self) -> Self::K {
self.a
}
}
// WithKey is important
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).unwrap();
assert_eq!(data_writer.topic(), &topic);
sourcepub fn publisher(&self) -> &Publisher
pub fn publisher(&self) -> &Publisher
Publisher assigned to this DataWriter
§Examples
let domain_participant = DomainParticipant::new(0).unwrap();
let qos = QosPolicyBuilder::new().build();
let publisher = domain_participant.create_publisher(&qos).unwrap();
#[derive(Serialize, Deserialize, Debug)]
struct SomeType { a: i32 }
impl Keyed for SomeType {
type K = i32;
fn key(&self) -> Self::K {
self.a
}
}
// WithKey is important
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).unwrap();
assert_eq!(data_writer.publisher(), &publisher);
sourcepub fn assert_liveliness(&self) -> WriteResult<(), ()>
pub fn assert_liveliness(&self) -> WriteResult<(), ()>
Manually asserts liveliness (use this instead of refresh) according to QoS
§Examples
let domain_participant = DomainParticipant::new(0).unwrap();
let qos = QosPolicyBuilder::new().build();
let publisher = domain_participant.create_publisher(&qos).unwrap();
#[derive(Serialize, Deserialize, Debug)]
struct SomeType { a: i32 }
impl Keyed for SomeType {
type K = i32;
fn key(&self) -> Self::K {
self.a
}
}
// WithKey is important
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).unwrap();
data_writer.assert_liveliness().unwrap();
sourcepub fn get_matched_subscriptions(&self) -> Vec<SubscriptionBuiltinTopicData>
pub fn get_matched_subscriptions(&self) -> Vec<SubscriptionBuiltinTopicData>
Unimplemented. Do not use.
§Examples
let domain_participant = DomainParticipant::new(0).unwrap();
let qos = QosPolicyBuilder::new().build();
let publisher = domain_participant.create_publisher(&qos).unwrap();
#[derive(Serialize, Deserialize, Debug)]
struct SomeType { a: i32 }
impl Keyed for SomeType {
type K = i32;
fn key(&self) -> Self::K {
self.a
}
}
// WithKey is important
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).unwrap();
for sub in data_writer.get_matched_subscriptions().iter() {
// do something
}
sourcepub fn dispose(
&self,
key: &<D as Keyed>::K,
source_timestamp: Option<Timestamp>
) -> WriteResult<(), ()>
pub fn dispose( &self, key: &<D as Keyed>::K, source_timestamp: Option<Timestamp> ) -> WriteResult<(), ()>
Disposes data instance with specified key
§Arguments
key
- Key of the instancesource_timestamp
- DDS source timestamp (None uses now as time as specified in DDS spec)
§Examples
let domain_participant = DomainParticipant::new(0).unwrap();
let qos = QosPolicyBuilder::new().build();
let publisher = domain_participant.create_publisher(&qos).unwrap();
#[derive(Serialize, Deserialize, Debug)]
struct SomeType { a: i32, val: usize }
impl Keyed for SomeType {
type K = i32;
fn key(&self) -> Self::K {
self.a
}
}
// WithKey is important
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).unwrap();
let some_data_1_1 = SomeType { a: 1, val: 3};
let some_data_1_2 = SomeType { a: 1, val: 4};
// different key
let some_data_2_1 = SomeType { a: 2, val: 5};
let some_data_2_2 = SomeType { a: 2, val: 6};
data_writer.write(some_data_1_1, None).unwrap();
data_writer.write(some_data_1_2, None).unwrap();
data_writer.write(some_data_2_1, None).unwrap();
data_writer.write(some_data_2_2, None).unwrap();
// disposes both some_data_1_1 and some_data_1_2. They are no longer offered by this writer to this topic.
data_writer.dispose(&1, None).unwrap();
source§impl<D, SA> DataWriter<D, SA>where
D: Keyed,
SA: SerializerAdapter<D>,
impl<D, SA> DataWriter<D, SA>where
D: Keyed,
SA: SerializerAdapter<D>,
pub async fn async_write( &self, data: D, source_timestamp: Option<Timestamp> ) -> WriteResult<(), D>
pub async fn async_write_with_options( &self, data: D, write_options: WriteOptions ) -> WriteResult<SampleIdentity, D>
sourcepub async fn async_wait_for_acknowledgments(&self) -> WriteResult<bool, ()>
pub async fn async_wait_for_acknowledgments(&self) -> WriteResult<bool, ()>
Like the synchronous version. But there is no timeout. Use asyncs to bring your own timeout.