zerodds-dcps-async 1.0.0-rc.1

Runtime-agnostic async wrappers around the ZeroDDS DCPS sync API (zerodds-async-1.0 spec): write/take Futures, SampleStream, DataAvailableStream, PublicationMatchedStream — kein Thread-Block, native Reader-Slot-Waker.
Documentation
// SPDX-License-Identifier: Apache-2.0
// Copyright 2026 ZeroDDS Contributors
//! AsyncPublisher — newtype.

use alloc::sync::Arc;

use zerodds_dcps::{DataWriterQos, DdsType, Publisher, Result, Topic};

use crate::AsyncDataWriter;

/// Async-Wrapper um `Publisher`.
#[derive(Clone)]
pub struct AsyncPublisher {
    inner: Arc<Publisher>,
}

impl AsyncPublisher {
    pub(crate) fn from_sync(inner: Publisher) -> Self {
        Self {
            inner: Arc::new(inner),
        }
    }

    /// Erstellt einen DataWriter.
    ///
    /// # Errors
    /// Wie `Publisher::create_datawriter`.
    pub fn create_datawriter<T: DdsType + Send + Sync + 'static>(
        &self,
        topic: &Topic<T>,
        qos: DataWriterQos,
    ) -> Result<AsyncDataWriter<T>> {
        let writer = self.inner.create_datawriter::<T>(topic, qos)?;
        Ok(AsyncDataWriter::from_sync(writer))
    }

    /// Liefert die zugrundeliegende sync-Variante.
    #[must_use]
    pub fn as_sync(&self) -> &Publisher {
        &self.inner
    }
}