Skip to main content

zerodds_dcps_async/
publisher.rs

1// SPDX-License-Identifier: Apache-2.0
2// Copyright 2026 ZeroDDS Contributors
3//! AsyncPublisher — newtype.
4
5use alloc::sync::Arc;
6
7use zerodds_dcps::{DataWriterQos, DdsType, Publisher, Result, Topic};
8
9use crate::AsyncDataWriter;
10
11/// Async-Wrapper um `Publisher`.
12#[derive(Clone)]
13pub struct AsyncPublisher {
14    inner: Arc<Publisher>,
15}
16
17impl AsyncPublisher {
18    pub(crate) fn from_sync(inner: Publisher) -> Self {
19        Self {
20            inner: Arc::new(inner),
21        }
22    }
23
24    /// Erstellt einen DataWriter.
25    ///
26    /// # Errors
27    /// Wie `Publisher::create_datawriter`.
28    pub fn create_datawriter<T: DdsType + Send + Sync + 'static>(
29        &self,
30        topic: &Topic<T>,
31        qos: DataWriterQos,
32    ) -> Result<AsyncDataWriter<T>> {
33        let writer = self.inner.create_datawriter::<T>(topic, qos)?;
34        Ok(AsyncDataWriter::from_sync(writer))
35    }
36
37    /// Liefert die zugrundeliegende sync-Variante.
38    #[must_use]
39    pub fn as_sync(&self) -> &Publisher {
40        &self.inner
41    }
42}