ddshow_types/
ids.rs

1//! All dataflow related ids
2
3use core::fmt::{self, Debug, Display, Write};
4use timely::logging::WorkerIdentifier;
5
6#[cfg(feature = "enable_abomonation")]
7use abomonation_derive::Abomonation;
8
9#[cfg(feature = "rkyv")]
10use rkyv_dep::{Archive, Deserialize as RkyvDeserialize, Serialize as RkyvSerialize};
11
12#[cfg(feature = "serde")]
13use serde_dep::{Deserialize as SerdeDeserialize, Serialize as SerdeSerialize};
14
15#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
16#[cfg_attr(
17    feature = "serde",
18    derive(SerdeSerialize, SerdeDeserialize),
19    serde(crate = "serde_dep", transparent)
20)]
21#[cfg_attr(
22    feature = "rkyv",
23    derive(Archive, RkyvSerialize, RkyvDeserialize),
24    archive(crate = "rkyv_dep", repr(transparent)),
25    archive_attr(derive(bytecheck::CheckBytes))
26)]
27#[cfg_attr(feature = "enable_abomonation", derive(Abomonation))]
28#[repr(transparent)]
29pub struct WorkerId {
30    worker: WorkerIdentifier,
31}
32
33impl WorkerId {
34    #[inline]
35    pub const fn new(worker: WorkerIdentifier) -> Self {
36        Self { worker }
37    }
38
39    #[inline]
40    pub const fn into_inner(self) -> WorkerIdentifier {
41        self.worker
42    }
43}
44
45impl From<usize> for WorkerId {
46    #[inline]
47    fn from(worker: usize) -> Self {
48        Self::new(worker)
49    }
50}
51
52impl Debug for WorkerId {
53    #[inline]
54    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
55        f.write_str("WorkerId(")?;
56        Display::fmt(&self.worker, f)?;
57        f.write_char(')')
58    }
59}
60
61impl Display for WorkerId {
62    #[inline]
63    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
64        Display::fmt(&self.worker, f)
65    }
66}
67
68#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
69#[cfg_attr(
70    feature = "serde",
71    derive(SerdeSerialize, SerdeDeserialize),
72    serde(crate = "serde_dep", transparent)
73)]
74#[cfg_attr(
75    feature = "rkyv",
76    derive(Archive, RkyvSerialize, RkyvDeserialize),
77    archive(crate = "rkyv_dep", repr(transparent)),
78    archive_attr(derive(bytecheck::CheckBytes))
79)]
80#[cfg_attr(feature = "enable_abomonation", derive(Abomonation))]
81#[repr(transparent)]
82pub struct OperatorId {
83    operator: usize,
84}
85
86impl OperatorId {
87    #[inline]
88    pub const fn new(operator: usize) -> Self {
89        Self { operator }
90    }
91
92    #[inline]
93    pub const fn into_inner(self) -> usize {
94        self.operator
95    }
96}
97
98impl From<PortId> for OperatorId {
99    #[inline]
100    fn from(port: PortId) -> Self {
101        Self::new(port.into_inner())
102    }
103}
104
105impl Debug for OperatorId {
106    #[inline]
107    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
108        f.write_str("OperatorId(")?;
109        Display::fmt(&self.operator, f)?;
110        f.write_char(')')
111    }
112}
113
114impl Display for OperatorId {
115    #[inline]
116    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
117        Display::fmt(&self.operator, f)
118    }
119}
120
121#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
122#[cfg_attr(
123    feature = "serde",
124    derive(SerdeSerialize, SerdeDeserialize),
125    serde(crate = "serde_dep", transparent)
126)]
127#[cfg_attr(
128    feature = "rkyv",
129    derive(Archive, RkyvSerialize, RkyvDeserialize),
130    archive(crate = "rkyv_dep", repr(transparent)),
131    archive_attr(derive(bytecheck::CheckBytes))
132)]
133#[cfg_attr(feature = "enable_abomonation", derive(Abomonation))]
134#[repr(transparent)]
135pub struct PortId {
136    port: usize,
137}
138
139impl PortId {
140    #[inline]
141    pub const fn new(port: usize) -> Self {
142        Self { port }
143    }
144
145    #[inline]
146    pub const fn into_inner(self) -> usize {
147        self.port
148    }
149
150    #[inline]
151    pub const fn zero() -> Self {
152        Self::new(0)
153    }
154
155    #[inline]
156    pub const fn is_zero(&self) -> bool {
157        self.port == 0
158    }
159}
160
161impl Debug for PortId {
162    #[inline]
163    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
164        f.write_str("PortId(")?;
165        Display::fmt(&self.port, f)?;
166        f.write_char(')')
167    }
168}
169
170impl Display for PortId {
171    #[inline]
172    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
173        Display::fmt(&self.port, f)
174    }
175}
176
177#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
178#[cfg_attr(
179    feature = "serde",
180    derive(SerdeSerialize, SerdeDeserialize),
181    serde(crate = "serde_dep", transparent)
182)]
183#[cfg_attr(
184    feature = "rkyv",
185    derive(Archive, RkyvSerialize, RkyvDeserialize),
186    archive(crate = "rkyv_dep", repr(transparent)),
187    archive_attr(derive(bytecheck::CheckBytes))
188)]
189#[cfg_attr(feature = "enable_abomonation", derive(Abomonation))]
190#[repr(transparent)]
191pub struct ChannelId {
192    channel: usize,
193}
194
195impl ChannelId {
196    #[inline]
197    pub const fn new(channel: usize) -> Self {
198        Self { channel }
199    }
200
201    #[inline]
202    pub const fn into_inner(self) -> usize {
203        self.channel
204    }
205}
206
207impl Debug for ChannelId {
208    #[inline]
209    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
210        f.write_str("ChannelId(")?;
211        Display::fmt(&self.channel, f)?;
212        f.write_char(')')
213    }
214}
215
216impl Display for ChannelId {
217    #[inline]
218    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
219        Display::fmt(&self.channel, f)
220    }
221}