1#[macro_export]
3macro_rules! dlog {
4 ($($arg:tt)*) => {
5 {
6 use ::std::sync::atomic::{AtomicU8, Ordering};
7 static ENABLED: AtomicU8 = AtomicU8::new(2); let enabled = match ENABLED.load(Ordering::Relaxed) {
9 0 => false,
10 1 => true,
11 _ => {
12 let val = ::std::env::var("VOX_DLOG").is_ok_and(|v| v == "1");
13 ENABLED.store(val as u8, Ordering::Relaxed);
14 val
15 }
16 };
17 if enabled {
18 eprintln!($($arg)*);
19 }
20 }
21 };
22}
23
24macro_rules! declare_id {
25 ($(#[$meta:meta])* $name:ident, $inner:ty) => {
26 $(#[$meta])*
27 #[derive(Facet, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone, Copy)]
28 #[repr(transparent)]
29 #[facet(transparent)]
30 pub struct $name(pub $inner);
31
32 impl ::std::fmt::Display for $name {
33 fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
34 write!(f, "{}", self.0)
35 }
36 }
37
38 impl $name {
39 pub fn has_parity(self, parity: crate::Parity) -> bool {
41 match parity {
42 crate::Parity::Even => self.0.is_multiple_of(2),
43 crate::Parity::Odd => !self.0.is_multiple_of(2),
44 }
45 }
46 }
47
48 impl crate::IdType for $name {
49 fn from_raw(raw: u64) -> Self {
50 Self(raw as $inner)
51 }
52 }
53
54 };
55}
56
57pub trait IdType: Copy {
59 fn from_raw(raw: u64) -> Self;
60}
61
62pub struct IdAllocator<T: IdType> {
68 next: u64,
69 _phantom: std::marker::PhantomData<T>,
70}
71
72impl<T: IdType> IdAllocator<T> {
73 pub fn new(parity: Parity) -> Self {
75 let next = match parity {
76 Parity::Odd => 1,
77 Parity::Even => 2,
78 };
79 Self {
80 next,
81 _phantom: std::marker::PhantomData,
82 }
83 }
84
85 pub fn alloc(&mut self) -> T {
87 let id = T::from_raw(self.next);
88 self.next += 2;
89 id
90 }
91}
92
93mod vox_error;
94pub use vox_error::*;
95
96mod services;
97pub use services::*;
98
99mod requests;
100pub use requests::*;
101
102mod message;
103pub use message::*;
104
105mod handshake;
106pub use handshake::*;
107
108mod selfref;
109pub use selfref::*;
110
111mod link;
112pub use link::*;
113
114mod conduit;
115pub use conduit::*;
116
117mod metadata;
118pub use metadata::*;
119
120mod retry_support;
121pub use retry_support::*;
122
123mod request_context;
124pub use request_context::*;
125
126mod server_middleware;
127pub use server_middleware::*;
128
129mod client_middleware;
130pub use client_middleware::*;
131
132mod observer;
133pub use observer::*;
134
135pub mod time;
136
137mod debug_snapshot;
138pub use debug_snapshot::*;
139
140mod calls;
141pub use calls::*;
142
143pub mod channel;
144pub use channel::*;
145
146pub mod fd;
147pub use fd::{FrameFds, collect_fds, frame_fds_len, provide_fds};
148#[cfg(unix)]
149pub use fd::{Fd, FdAdapter, SCM_MAX_FD};
150
151mod shape_classify;
152pub use shape_classify::*;
153
154mod method_identity;
155pub use method_identity::*;
156
157pub mod schema;
158pub use schema::*;
159
160pub struct WithTracker<T> {
164 pub value: T,
165 pub tracker: std::sync::Arc<SchemaRecvTracker>,
166 pub fds: crate::FrameFds,
171}
172
173impl<T> std::fmt::Debug for WithTracker<T> {
174 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
175 f.debug_struct("WithTracker").finish_non_exhaustive()
176 }
177}
178
179impl<T> std::ops::Deref for WithTracker<T> {
180 type Target = T;
181 fn deref(&self) -> &T {
182 &self.value
183 }
184}
185
186impl<T> std::ops::DerefMut for WithTracker<T> {
187 fn deref_mut(&mut self) -> &mut T {
188 &mut self.value
189 }
190}