pub fn write(&self, data: D, source_timestamp: Option<Timestamp>) -> Result<()> {
    let mut ddsdata = DDSData::from(&data, source_timestamp);
    // TODO key value should be unique always. This is not always unique.
    // If sample with same values is given then hash is same for both samples.
    // TODO FIX THIS
    ddsdata.value_key_hash = data.get_key().into_hash_key();

    let _data_sample = match source_timestamp {
      // TODO: fix this to use something else than new_deprecated.
      // We cannot generate DataSample at the writer side, because most of the
      // SampleInfo fields cannot be known.
      Some(t) => DataSample::new_deprecated(t, data, self.get_guid()),
      None => DataSample::new_deprecated(Timestamp::now(), data, self.get_guid()),
    };

    match self
      .cc_upload
      .try_send(WriterCommand::DDSData { data: ddsdata })
    {
      Ok(_) => {
        self.refresh_manual_liveliness();
        Ok(())
      }
      Err(e) => {
        warn!("Failed to write new data. {:?}", e);
        Err(Error::OutOfResources)
      }
    }
  }
/// Writes single data instance to a topic.
///
/// # Examples
///
/// ```
/// # use serde::{Serialize, Deserialize};
/// # use rustdds::dds::DomainParticipant;
/// # use rustdds::dds::qos::QosPolicyBuilder;
/// # use rustdds::dds::data_types::TopicKind;
/// # use rustdds::dds::With_Key_DataWriter as DataWriter;
/// # use rustdds::dds::traits::Keyed;
/// # use rustdds::serialization::CDRSerializerAdapter;
/// #
/// let domain_participant = DomainParticipant::new(0);
/// let qos = QosPolicyBuilder::new().build();
/// let publisher = domain_participant.create_publisher(&qos).unwrap();
///
/// #[derive(Serialize, Deserialize)]
/// struct SomeType { a: i32 }
/// impl Keyed for SomeType {
///   type K = i32;
///
///   fn get_key(&self) -> Self::K {
///     self.a
///   }
/// }
///
/// // WithKey is important
/// let topic = domain_participant.create_topic("some_topic", "SomeType", &qos, TopicKind::WithKey).unwrap();
/// let data_writer = publisher.create_datawriter::<SomeType, CDRSerializerAdapter<_>>(None, topic, None).unwrap();
///
/// let some_data = SomeType { a: 1 };
/// data_writer.write(some_data, None).unwrap();
/// ```
Writes single data instance to a topic.
Writes single data instance to a topic .
pub fn write(&self, data: D, source_timestamp: Option<Timestamp>) -> Result<()> {
    let mut ddsdata = DDSData::from(&data, source_timestamp);
    // TODO key value should be unique always. This is not always unique.
    // If sample with same values is given then hash is same for both samples.
    // TODO FIX THIS
    ddsdata.value_key_hash = data.get_key().into_hash_key();
    let _data_sample = match source_timestamp {
      // TODO: fix this to use something else than new_deprecated.
      // We cannot generate DataSample at the writer side, because most of the
      // SampleInfo fields cannot be known.
      Some(t) => DataSample::new_deprecated(t, data, self.get_guid()),
      None => DataSample::new_deprecated(Timestamp::now(), data, self.get_guid()),
    };
    match self
      .cc_upload
      .try_send(WriterCommand::DDSData { data: ddsdata })
    {
      Ok(_) => {
        self.refresh_manual_liveliness();
        Ok(())
      }
      Err(e) => {
        warn!("Failed to write new data. {:?}", e);
        Err(Error::OutOfResources)
      }
    }
  }
pub fn write ( & self , data : D , source_timestamp : Option < Timestamp > ) -> Result < ( ) > { let mut ddsdata = DDSData :: from ( & data , source_timestamp ) ; // TODO key value should be unique always. This is not always unique. // If sample with same values is given then hash is same for both samples. // TODO FIX THIS ddsdata . value_key_hash = data . get_key ( ) . into_hash_key ( ) ; let _data_sample = match source_timestamp { // TODO: fix this to use something else than new_deprecated. // We cannot generate DataSample at the writer side, because most of the // SampleInfo fields cannot be known. Some ( t ) => DataSample :: new_deprecated ( t , data , self . get_guid ( ) ) , None => DataSample :: new_deprecated ( Timestamp :: now ( ) , data , self . get_guid ( ) ) , } ; match self . cc_upload . try_send ( WriterCommand :: DDSData { data : ddsdata } ) { Ok ( _ ) => { self . refresh_manual_liveliness ( ) ; Ok ( ( ) ) } Err ( e ) => { warn ! ( " " e ) ; Err ( Error :: OutOfResources ) } } }
Writes single data instance to a topic.
Writes single data instance to a topic .
&self
data
D
source_timestamp
Option<Timestamp>
examples
None
use serde::{serialize, deserialize};
None
use rustdds::dds::domainparticipant;
None
use rustdds::dds::qos::qospolicybuilder;
None
use rustdds::dds::data_types::topickind;
None
use rustdds::dds::with_key_datawriter as datawriter;
None
use rustdds::dds::traits::keyed;
None
use rustdds::serialization::cdrserializeradapter;
let domain_participant = DomainParticipant::new(0);
let qos = QosPolicyBuilder::new().build();
let publisher = domain_participant.create_publisher(&qos).unwrap().
let domain_participant = DomainParticipant :: new ( 0 ) ; let qos = QosPolicyBuilder :: new () . build () ; let publisher = domain_participant . create_publisher ( &qos ) . unwrap () .
[derive(serialize, deserialize)]
struct SomeType { a: i32 }
impl Keyed for SomeType {
type K = i32.



WithKey is important
let topic = domain_participant.create_topic("some_topic", "SomeType", &qos, TopicKind::WithKey).unwrap();
let data_writer = publisher.create_datawriter::>(None, topic, None).unwrap().

let some_data = SomeType { a: 1 };
data_writer.write(some_data, None).unwrap();
```
struct SomeType { a : i32 } impl Keyed for SomeType { type K = i32 . WithKey is important let topic = domain_participant . create_topic ( " some_topic " " SomeType " &qos TopicKind :: WithKey ) . unwrap () ; let data_writer = publisher . create_datawriter :: > ( None topic None ) . unwrap () . let some_data = SomeType { a : 1 } ; data_writer . write ( some_data None ) . unwrap () ; ` ` `