Skip to main content

nros_node/
publisher.rs

1//! Publisher handle
2
3use core::marker::PhantomData;
4
5/// Handle to a publisher
6///
7/// This is a lightweight handle that references a publisher registered
8/// with a Node. The type parameter `M` ensures type safety when publishing.
9#[derive(Debug)]
10pub struct PublisherHandle<M> {
11    index: usize,
12    _marker: PhantomData<M>,
13}
14
15impl<M> PublisherHandle<M> {
16    /// Create a new publisher handle
17    pub(crate) fn new(index: usize) -> Self {
18        Self {
19            index,
20            _marker: PhantomData,
21        }
22    }
23
24    /// Get the internal index
25    pub(crate) fn index(&self) -> usize {
26        self.index
27    }
28
29    /// Convert to an untyped handle (for internal use)
30    #[allow(dead_code)] // Will be used for topic info lookup
31    pub(crate) fn untyped(&self) -> PublisherHandle<()> {
32        PublisherHandle {
33            index: self.index,
34            _marker: PhantomData,
35        }
36    }
37}
38
39impl<M> Clone for PublisherHandle<M> {
40    fn clone(&self) -> Self {
41        *self
42    }
43}
44
45impl<M> Copy for PublisherHandle<M> {}
46
47impl<M> PartialEq for PublisherHandle<M> {
48    fn eq(&self, other: &Self) -> bool {
49        self.index == other.index
50    }
51}
52
53impl<M> Eq for PublisherHandle<M> {}