Skip to main content

DataReader

Struct DataReader 

Source
pub struct DataReader<T> { /* private fields */ }
Expand description

A DDS data reader (DDS 1.4, 2.2.2.5.3) of samples of type T: a TopicType, or DynamicData for a topic of a type known at run time (a DynamicDataReader, DDS-XTypes 1.3, 7.5.2.12).

Samples that cannot be deserialized as T are dropped when they are read or taken. Dropping the reader tells the other participants it is gone.

Implementations§

Source§

impl<T> DataReader<T>

Source

pub fn guid(&self) -> Guid

The reader’s GUID.

Source

pub fn take(&self) -> Vec<Sample<T>>

Removes and returns the samples received, in the order they arrived.

Source

pub fn read(&self) -> Vec<Sample<T>>

Returns the samples received, in the order they arrived, and leaves them in the reader, marked as read.

Source

pub fn take_with(&self, filter: StateFilter) -> Vec<Sample<T>>

Like Self::take, for the samples whose states pass filter.

Source

pub fn read_with(&self, filter: StateFilter) -> Vec<Sample<T>>

Like Self::read, for the samples whose states pass filter.

Source

pub fn take_instance(&self, instance: InstanceHandle) -> Vec<Sample<T>>

Takes the samples of one instance (take_instance).

Source

pub fn read_instance(&self, instance: InstanceHandle) -> Vec<Sample<T>>

Reads the samples of one instance (read_instance).

Source

pub fn take_next_instance( &self, previous: Option<InstanceHandle>, filter: StateFilter, ) -> Vec<Sample<T>>

Takes the samples of the instance after previous, in handle order, that has samples passing filter; from the first instance when previous is None (take_next_instance). Empty when there is no such instance.

Source

pub fn read_next_instance( &self, previous: Option<InstanceHandle>, filter: StateFilter, ) -> Vec<Sample<T>>

Like Self::take_next_instance, reading (read_next_instance).

Source

pub fn max_samples(&self, max_samples: usize) -> MaxSamples<'_, T>

The reads and takes of at most max_samples samples (the max_samples argument of DDS 1.4, 2.2.2.5.3.8): the first to arrive of those selected. The others stay in the reader as they were.

Source

pub fn lookup_instance(&self, instance: &T) -> Option<InstanceHandle>

The handle of the instance of instance (lookup_instance), if the reader has it.

Source

pub fn get_key_value(&self, instance: InstanceHandle) -> Option<T>

The key of an instance (get_key_value): the last value received for it, whose key members identify it. None if the reader has not received a value for it, or has forgotten the instance: one with no samples left and no writers is forgotten at the read or take after the one that emptied it.

Source

pub fn wait_for_data(&self, timeout: Duration) -> bool

Waits until there is a sample not yet read, or timeout passes. Returns whether there is one.

Source

pub fn set_listener( &self, listener: impl DataReaderListener<T> + 'static, mask: StatusMask, )
where T: 'static,

Sets the listener (set_listener), replacing any earlier one: its methods are called for the statuses in mask when they change. See DataReaderListener.

Source

pub fn on_data_available( &self, f: impl Fn(&DataReader<T>) + Send + Sync + 'static, )
where T: 'static,

Sets a listener for DATA_AVAILABLE alone: f is called with the reader when samples arrive. It may take them, or send to a channel:

let (tx, rx) = std::sync::mpsc::channel();
reader.on_data_available(move |r| {
    for s in r.take() {
        let _ = tx.send(s);
    }
});
Source

pub fn clear_listener(&self)

Removes the listener.

Source

pub fn status_changes(&self) -> StatusMask

The statuses changed since they were last read (get_status_changes).

Source

pub fn status_condition(&self) -> StatusCondition

The reader’s StatusCondition (get_statuscondition).

Source

pub fn create_readcondition(&self, filter: StateFilter) -> ReadCondition

A ReadCondition that is true while the reader has samples whose states pass filter (create_readcondition). Dropping every clone of it deletes it.

Source

pub fn take_w_condition( &self, condition: &ReadCondition, ) -> Result<Vec<Sample<T>>>

Takes the samples condition is true for (take_w_condition). Fails with Error::PreconditionNotMet for a condition of another reader.

Source

pub fn read_w_condition( &self, condition: &ReadCondition, ) -> Result<Vec<Sample<T>>>

Reads the samples condition is true for (read_w_condition).

Source

pub fn subscription_matched_status(&self) -> MatchedStatus

The SUBSCRIPTION_MATCHED status: the writers matched. Reading it resets the *_change counts.

Source

pub fn sample_lost_status(&self) -> SampleLostStatus

The SAMPLE_LOST status: samples of matched writers that never arrived (gaps in their sequence numbers, for a BEST_EFFORT reader). Reading it resets total_count_change.

Source

pub fn matched_publications(&self) -> Vec<Guid>

The writers matched now (get_matched_publications).

Source

pub fn requested_incompatible_qos_status(&self) -> IncompatibleQosStatus

The REQUESTED_INCOMPATIBLE_QOS status: writers of the same topic, type and partition that this reader did not match because of their QoS. Reading it resets total_count_change.

Source

pub fn sample_rejected_status(&self) -> SampleRejectedStatus

The SAMPLE_REJECTED status: samples dropped because of the reader’s RESOURCE_LIMITS. Reading it resets total_count_change.

Source

pub fn liveliness_changed_status(&self) -> LivelinessChangedStatus

The LIVELINESS_CHANGED status: how many matched writers are alive and how many are not. Reading it resets the *_change counts.

Source

pub fn requested_deadline_missed_status(&self) -> DeadlineMissedStatus

The REQUESTED_DEADLINE_MISSED status: DEADLINE periods in which an alive instance got no sample. Reading it resets total_count_change.

Source

pub fn wait_for_publications(&self, count: usize, timeout: Duration) -> bool

Waits until at least count writers are matched, or timeout passes. Returns whether they are.

Source§

impl<T: PlainType> DataReader<T>

Source

pub fn take_loaned(&self) -> Vec<Sample<ReadLoan<T>>>

Removes and returns the samples received, in the order they arrived, without copying them: the samples that a writer of this host loaned (see DataWriter::loan_sample) are read in place in its shared memory, and its slot stays held until the ReadLoan is dropped. Other samples are deserialized.

Source

pub fn read_loaned(&self) -> Vec<Sample<ReadLoan<T>>>

Like Self::take_loaned, leaving the samples in the reader, marked as read.

Source

pub fn take_loaned_max(&self, max: usize) -> Vec<Sample<ReadLoan<T>>>

Like Self::take_loaned, at most max samples.

Trait Implementations§

Source§

impl<T> Debug for DataReader<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> Drop for DataReader<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl<T> !RefUnwindSafe for DataReader<T>

§

impl<T> !UnwindSafe for DataReader<T>

§

impl<T> Forget for DataReader<T>

§

impl<T> Freeze for DataReader<T>
where Arc<dyn SampleType<T>>: Freeze,

§

impl<T> Move for DataReader<T>

§

impl<T> Send for DataReader<T>
where Arc<dyn SampleType<T>>: Send,

§

impl<T> Sync for DataReader<T>
where Arc<dyn SampleType<T>>: Sync,

§

impl<T> Unpin for DataReader<T>
where Arc<dyn SampleType<T>>: Unpin,

§

impl<T> UnsafeUnpin for DataReader<T>
where Arc<dyn SampleType<T>>: UnsafeUnpin,

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

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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.