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>,

source

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();
source

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();
source

pub fn write_with_options( &self, data: D, write_options: WriteOptions ) -> WriteResult<SampleIdentity, D>

source

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 acknowledged
  • Ok(false)- timed out waiting for acknowledgments
  • Err(_) - 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));
source

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);
source

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);
source

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();
source

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
}
source

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 instance
  • source_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>,

source

pub async fn async_write( &self, data: D, source_timestamp: Option<Timestamp> ) -> WriteResult<(), D>

source

pub async fn async_write_with_options( &self, data: D, write_options: WriteOptions ) -> WriteResult<SampleIdentity, D>

source

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.

Trait Implementations§

source§

impl<D, SA> Drop for DataWriter<D, SA>
where D: Keyed, SA: SerializerAdapter<D>,

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl<D, SA> HasQoSPolicy for DataWriter<D, SA>
where D: Keyed, SA: SerializerAdapter<D>,

source§

impl<D, SA> RTPSEntity for DataWriter<D, SA>
where D: Keyed, SA: SerializerAdapter<D>,

source§

fn guid(&self) -> GUID

source§

fn entity_id(&self) -> EntityId

source§

fn guid_prefix(&self) -> GuidPrefix

source§

impl<'a, D, SA> StatusEvented<'a, DataWriterStatus, StatusReceiverStream<'a, DataWriterStatus>> for DataWriter<D, SA>
where D: Keyed, SA: SerializerAdapter<D>,

Auto Trait Implementations§

§

impl<D, SA = CDRSerializerAdapter<D>> !Freeze for DataWriter<D, SA>

§

impl<D, SA = CDRSerializerAdapter<D>> !RefUnwindSafe for DataWriter<D, SA>

§

impl<D, SA> Send for DataWriter<D, SA>
where D: Send, SA: Send,

§

impl<D, SA> Sync for DataWriter<D, SA>
where D: Sync, SA: Sync,

§

impl<D, SA> Unpin for DataWriter<D, SA>
where D: Unpin, SA: Unpin,

§

impl<D, SA = CDRSerializerAdapter<D>> !UnwindSafe for DataWriter<D, SA>

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, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V