Struct rustdds::dds::no_key::DataReader
source · pub struct DataReader<D, DA: DeserializerAdapter<D> = CDRDeserializerAdapter<D>> { /* private fields */ }
Expand description
DDS DataReader for no key topics.
§Examples
use serde::{Serialize, Deserialize};
use rustdds::*;
use rustdds::no_key::DataReader;
use rustdds::serialization::CDRDeserializerAdapter;
let domain_participant = DomainParticipant::new(0).unwrap();
let qos = QosPolicyBuilder::new().build();
let subscriber = domain_participant.create_subscriber(&qos).unwrap();
#[derive(Serialize, Deserialize)]
struct SomeType {}
// NoKey is important
let topic = domain_participant.create_topic("some_topic".to_string(), "SomeType".to_string(), &qos, TopicKind::NoKey).unwrap();
let data_reader = subscriber.create_datareader_no_key::<SomeType, CDRDeserializerAdapter<_>>(&topic, None);
Implementations§
source§impl<D: 'static, DA> DataReader<D, DA>where
DA: DeserializerAdapter<D>,
impl<D: 'static, DA> DataReader<D, DA>where
DA: DeserializerAdapter<D>,
sourcepub fn read(
&mut self,
max_samples: usize,
read_condition: ReadCondition
) -> ReadResult<Vec<DataSample<&D>>>
pub fn read( &mut self, max_samples: usize, read_condition: ReadCondition ) -> ReadResult<Vec<DataSample<&D>>>
Reads amount of samples found with max_samples
and read_condition
parameters.
§Arguments
max_samples
- Limits maximum amount of samples readread_condition
- Limits results by condition
§Examples
let mut data_reader = subscriber.create_datareader_no_key::<SomeType, CDRDeserializerAdapter<_>>(&topic, None).unwrap();
let data = data_reader.read(10, ReadCondition::not_read());
sourcepub fn take(
&mut self,
max_samples: usize,
read_condition: ReadCondition
) -> ReadResult<Vec<DataSample<D>>>
pub fn take( &mut self, max_samples: usize, read_condition: ReadCondition ) -> ReadResult<Vec<DataSample<D>>>
Takes amount of sample found with max_samples
and read_condition
parameters.
§Arguments
max_samples
- Limits maximum amount of samples readread_condition
- Limits results by condition
§Examples
let mut data_reader = subscriber.create_datareader_no_key::<SomeType, CDRDeserializerAdapter<_>>(&topic, None).unwrap();
let data = data_reader.take(10, ReadCondition::not_read());
sourcepub fn read_next_sample(&mut self) -> ReadResult<Option<DataSample<&D>>>
pub fn read_next_sample(&mut self) -> ReadResult<Option<DataSample<&D>>>
Reads next unread sample
§Examples
let mut data_reader = subscriber.create_datareader_no_key::<SomeType, CDRDeserializerAdapter<_>>(&topic, None).unwrap();
while let Ok(Some(data)) = data_reader.read_next_sample() {
// Do something
}
sourcepub fn take_next_sample(&mut self) -> ReadResult<Option<DataSample<D>>>
pub fn take_next_sample(&mut self) -> ReadResult<Option<DataSample<D>>>
Takes next unread sample
§Examples
let mut data_reader = subscriber.create_datareader_no_key::<SomeType, CDRDeserializerAdapter<_>>(&topic, None).unwrap();
while let Ok(Some(data)) = data_reader.take_next_sample() {
// Do something
}
sourcepub fn iterator(&mut self) -> ReadResult<impl Iterator<Item = &D>>
pub fn iterator(&mut self) -> ReadResult<impl Iterator<Item = &D>>
Produces an iterator over the currently available NOT_READ samples.
Yields only payload data, not SampleInfo metadata
This is not called iter()
because it takes a mutable reference to self.
§Examples
let mut data_reader = subscriber.create_datareader_no_key::<SomeType, CDRDeserializerAdapter<_>>(&topic, None).unwrap();
for data in data_reader.iterator() {
// Do something
}
sourcepub fn conditional_iterator(
&mut self,
read_condition: ReadCondition
) -> ReadResult<impl Iterator<Item = &D>>
pub fn conditional_iterator( &mut self, read_condition: ReadCondition ) -> ReadResult<impl Iterator<Item = &D>>
Produces an iterator over the samples filtered by given condition. Yields only payload data, not SampleInfo metadata
§Examples
let mut data_reader = subscriber.create_datareader_no_key::<SomeType, CDRDeserializerAdapter<_>>(&topic, None).unwrap();
for data in data_reader.conditional_iterator(ReadCondition::any()) {
// Do something
}
sourcepub fn into_iterator(&mut self) -> ReadResult<impl Iterator<Item = D>>
pub fn into_iterator(&mut self) -> ReadResult<impl Iterator<Item = D>>
Produces an iterator over the currently available NOT_READ samples.
Yields only payload data, not SampleInfo metadata
Removes samples from DataReader
.
Note! If the iterator is only partially consumed, all the
samples it could have provided are still removed from the Datareader
.
§Examples
let mut data_reader = subscriber.create_datareader_no_key::<SomeType, CDRDeserializerAdapter<_>>(&topic, None).unwrap();
for data in data_reader.into_iterator() {
// Do something
}
sourcepub fn into_conditional_iterator(
&mut self,
read_condition: ReadCondition
) -> ReadResult<impl Iterator<Item = D>>
pub fn into_conditional_iterator( &mut self, read_condition: ReadCondition ) -> ReadResult<impl Iterator<Item = D>>
Produces an iterator over the samples filtered by given condition.
Yields only payload data, not SampleInfo metadata
Note! If the iterator is only partially consumed, all the
samples it could have provided are still removed from the Datareader
.
§Examples
let mut data_reader = subscriber.create_datareader_no_key::<SomeType, CDRDeserializerAdapter<_>>(&topic, None).unwrap();
for data in data_reader.into_conditional_iterator(ReadCondition::any()) {
// Do something
}
sourcepub fn async_sample_stream(self) -> DataReaderStream<D, DA>
pub fn async_sample_stream(self) -> DataReaderStream<D, DA>
An async stream for reading the (bare) data samples
Trait Implementations§
source§impl<D, DA> Evented for DataReader<D, DA>where
DA: DeserializerAdapter<D>,
impl<D, DA> Evented for DataReader<D, DA>where
DA: DeserializerAdapter<D>,
WARNING! UNTESTED
source§impl<D, DA> HasQoSPolicy for DataReader<D, DA>where
D: 'static,
DA: DeserializerAdapter<D>,
impl<D, DA> HasQoSPolicy for DataReader<D, DA>where
D: 'static,
DA: DeserializerAdapter<D>,
fn qos(&self) -> QosPolicies
source§impl<D, DA> RTPSEntity for DataReader<D, DA>where
D: 'static,
DA: DeserializerAdapter<D>,
impl<D, DA> RTPSEntity for DataReader<D, DA>where
D: 'static,
DA: DeserializerAdapter<D>,
source§impl<D, DA> Source for DataReader<D, DA>where
DA: DeserializerAdapter<D>,
impl<D, DA> Source for DataReader<D, DA>where
DA: DeserializerAdapter<D>,
WARNING! UNTESTED