mbus-ffi 0.13.0

Native C FFI and browser WASM bindings for modbus-rs client APIs, with optional generated server bindings
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
//! Static server pool — mirrors the client pool design in `super::super::client::pool`.
//!
//! ## ID Encoding
//!
//! `MbusServerId` is a `u16` with the following layout:
//!
//! ```text
//!  High byte (pool tag)   Low byte (slot index)
//!  ──────────────────── ─────────────────────────
//!    0x10                0x00..=0xFE  →  TCP server slot
//!    0x11                0x00..=0xFE  →  Serial RTU server slot
//!    0xFF                0xFF         →  MBUS_INVALID_SERVER_ID (0xFFFF)
//! ```
//!
//! ## Safety Contract
//!
//! Same as the client pool: `UnsafeCell` + external locking via `mbus_pool_lock` /
//! `mbus_pool_unlock` hooks for pool-level operations, and `mbus_server_lock` /
//! `mbus_server_unlock` hooks for per-server operations.

use core::cell::UnsafeCell;
use core::mem::MaybeUninit;
use core::sync::atomic::{AtomicBool, Ordering};

use mbus_server::ServerServices;

use super::app::CServerApp;
#[cfg(any(feature = "serial-rtu", feature = "serial-ascii"))]
use crate::MAX_SERIAL_SERVERS;
#[cfg(feature = "network-tcp")]
use crate::MAX_TCP_SERVERS;
use crate::c::error::MbusStatusCode;
#[cfg(feature = "internal-lock-stubs")]
use crate::c::lock_stubs::*;
#[cfg(feature = "serial-ascii")]
use crate::c::transport::CAsciiTransport;
#[cfg(feature = "serial-rtu")]
#[cfg(any(feature = "serial-rtu", feature = "serial-ascii"))]
use crate::c::transport::CRtuTransport;
#[cfg(feature = "network-tcp")]
use crate::c::transport::CTcpTransport;

// ── Constants ─────────────────────────────────────────────────────────────────

/// Queue depth (max concurrent in-flight requests) for TCP servers.
#[cfg(feature = "network-tcp")]
pub(super) const SERVER_TCP_QUEUE_DEPTH: usize = 8;
/// Queue depth for serial servers (half-duplex = 1).
#[cfg(any(feature = "serial-rtu", feature = "serial-ascii"))]
pub(super) const SERVER_SERIAL_QUEUE_DEPTH: usize = 1;

/// Server ID type: an opaque `u16` index into one of the server sub-pools.
pub type MbusServerId = u16;

/// Sentinel value meaning "no valid server" / creation failed.
pub const MBUS_INVALID_SERVER_ID: MbusServerId = 0xFFFF;

/// Pool tag for TCP servers.
#[cfg(feature = "network-tcp")]
const TAG_TCP_SERVER: u8 = 0x10;
/// Pool tag for Serial RTU servers.
#[cfg(feature = "serial-rtu")]
const TAG_SERIAL_RTU_SERVER: u8 = 0x11;
/// Pool tag for Serial ASCII servers.
#[cfg(feature = "serial-ascii")]
const TAG_SERIAL_ASCII_SERVER: u8 = 0x12;

// ── Extern locks ──────────────────────────────────────────────────────────────

#[cfg(not(feature = "internal-lock-stubs"))]
unsafe extern "C" {
    /// Lock the global server pool (used only during server creation/destruction).
    fn mbus_pool_lock();
    /// Unlock the global server pool.
    fn mbus_pool_unlock();

    /// Lock a specific server instance.
    fn mbus_server_lock(id: MbusServerId);
    /// Unlock a specific server instance.
    fn mbus_server_unlock(id: MbusServerId);
}

/// RAII guard for the server pool lock.
pub(super) struct ServerPoolLockGuard;
impl ServerPoolLockGuard {
    pub(super) fn new() -> Self {
        unsafe { mbus_pool_lock() };
        Self
    }
}
impl Drop for ServerPoolLockGuard {
    fn drop(&mut self) {
        unsafe { mbus_pool_unlock() };
    }
}

/// RAII guard for a per-server lock.
pub(super) struct ServerLockGuard(MbusServerId);
impl ServerLockGuard {
    pub(super) fn new(id: MbusServerId) -> Self {
        unsafe { mbus_server_lock(id) };
        Self(id)
    }
}
impl Drop for ServerLockGuard {
    fn drop(&mut self) {
        unsafe { mbus_server_unlock(self.0) };
    }
}

/// RAII guard that clears a borrow flag on drop.
pub(super) struct ServerBorrowGuard<'a>(&'a AtomicBool);
impl<'a> ServerBorrowGuard<'a> {
    pub(super) fn new(flag: &'a AtomicBool) -> Self {
        Self(flag)
    }
}
impl Drop for ServerBorrowGuard<'_> {
    fn drop(&mut self) {
        self.0.store(false, Ordering::SeqCst);
    }
}

// ── Server inner types ────────────────────────────────────────────────────────

/// Fully-specialised TCP server type stored in the pool.
#[cfg(feature = "network-tcp")]
pub(super) type TcpServerInner = ServerServices<CTcpTransport, CServerApp, SERVER_TCP_QUEUE_DEPTH>;
/// Fully-specialised Serial RTU server type.
#[cfg(feature = "serial-rtu")]
pub(super) type SerialRtuServerInner =
    ServerServices<CRtuTransport, CServerApp, SERVER_SERIAL_QUEUE_DEPTH>;
/// Fully-specialised Serial ASCII server type.
#[cfg(feature = "serial-ascii")]
pub(super) type SerialAsciiServerInner =
    ServerServices<CAsciiTransport, CServerApp, SERVER_SERIAL_QUEUE_DEPTH>;

// ── ID helpers ────────────────────────────────────────────────────────────────

/// Return the pool tag encoded in the high byte of a server id.
///
/// The tag identifies the server type (TCP, Serial RTU, Serial ASCII).
#[inline(always)]
pub(super) fn server_id_tag(id: MbusServerId) -> u8 {
    (id >> 8) as u8
}

/// Return the slot index encoded in the low byte of a server id.
#[inline(always)]
pub(super) fn server_id_index(id: MbusServerId) -> usize {
    (id & 0xFF) as usize
}

/// Encode a pool tag and slot index into a single opaque `u16` server id.
#[inline(always)]
pub(super) fn encode_server_id(tag: u8, index: usize) -> MbusServerId {
    ((tag as u16) << 8) | (index as u16)
}

#[cfg(feature = "network-tcp")]
#[inline(always)]
/// Return true if the id is a valid TCP server id.
pub(super) fn is_tcp_server_id(id: MbusServerId) -> bool {
    id != MBUS_INVALID_SERVER_ID && server_id_tag(id) == TAG_TCP_SERVER
}

#[cfg(feature = "serial-rtu")]
#[inline(always)]
/// Return true if the id is a valid Serial RTU server id.
pub(super) fn is_serial_rtu_server_id(id: MbusServerId) -> bool {
    id != MBUS_INVALID_SERVER_ID && server_id_tag(id) == TAG_SERIAL_RTU_SERVER
}

#[cfg(feature = "serial-ascii")]
#[inline(always)]
/// Return true if the id is a valid Serial ASCII server id.
pub(super) fn is_serial_ascii_server_id(id: MbusServerId) -> bool {
    id != MBUS_INVALID_SERVER_ID && server_id_tag(id) == TAG_SERIAL_ASCII_SERVER
}

#[cfg(any(feature = "serial-rtu", feature = "serial-ascii"))]
#[inline(always)]
/// Return true if the id is a valid Serial server id (RTU or ASCII).
pub(super) fn is_serial_server_id(id: MbusServerId) -> bool {
    #[cfg(all(feature = "serial-rtu", feature = "serial-ascii"))]
    return is_serial_rtu_server_id(id) || is_serial_ascii_server_id(id);
    #[cfg(all(feature = "serial-rtu", not(feature = "serial-ascii")))]
    return is_serial_rtu_server_id(id);
    #[cfg(all(feature = "serial-ascii", not(feature = "serial-rtu")))]
    return is_serial_ascii_server_id(id);
}

// ── Typed slot ────────────────────────────────────────────────────────────────

struct Slot<T> {
    occupied: bool,
    value: MaybeUninit<T>,
    borrow_flag: AtomicBool,
}

impl<T> Slot<T> {
    /// Create an empty slot that is not occupied and has no value.
    const fn empty() -> Self {
        Self {
            occupied: false,
            value: MaybeUninit::uninit(),
            borrow_flag: AtomicBool::new(false),
        }
    }
}

// ── Pool struct ───────────────────────────────────────────────────────────────

struct ServerPool {
    #[cfg(feature = "network-tcp")]
    tcp_slots: [Slot<TcpServerInner>; MAX_TCP_SERVERS],
    #[cfg(feature = "serial-rtu")]
    serial_rtu_slots: [Slot<SerialRtuServerInner>; MAX_SERIAL_SERVERS],
    #[cfg(feature = "serial-ascii")]
    serial_ascii_slots: [Slot<SerialAsciiServerInner>; MAX_SERIAL_SERVERS],
}

impl ServerPool {
    /// Initialise all slot arrays with empty slots.
    const fn new() -> Self {
        Self {
            #[cfg(feature = "network-tcp")]
            tcp_slots: [const { Slot::empty() }; MAX_TCP_SERVERS],
            #[cfg(feature = "serial-rtu")]
            serial_rtu_slots: [const { Slot::empty() }; MAX_SERIAL_SERVERS],
            #[cfg(feature = "serial-ascii")]
            serial_ascii_slots: [const { Slot::empty() }; MAX_SERIAL_SERVERS],
        }
    }

    #[cfg(feature = "network-tcp")]
    /// Allocate a TCP server in the pool and return its id.
    fn allocate_tcp(&mut self, value: TcpServerInner) -> Option<MbusServerId> {
        if MAX_TCP_SERVERS == 1 {
            let slot = &mut self.tcp_slots[0];
            if !slot.occupied {
                slot.value = MaybeUninit::new(value);
                slot.borrow_flag.store(false, Ordering::SeqCst);
                slot.occupied = true;
                return Some(encode_server_id(TAG_TCP_SERVER, 0));
            }
            return None;
        }
        for (i, slot) in self.tcp_slots.iter_mut().enumerate() {
            if !slot.occupied {
                slot.value = MaybeUninit::new(value);
                slot.borrow_flag.store(false, Ordering::SeqCst);
                slot.occupied = true;
                return Some(encode_server_id(TAG_TCP_SERVER, i));
            }
        }
        None
    }

    #[cfg(feature = "serial-rtu")]
    /// Allocate a Serial RTU server in the pool and return its id.
    fn allocate_serial_rtu(&mut self, value: SerialRtuServerInner) -> Option<MbusServerId> {
        if MAX_SERIAL_SERVERS == 1 {
            let slot = &mut self.serial_rtu_slots[0];
            if !slot.occupied {
                slot.value = MaybeUninit::new(value);
                slot.borrow_flag.store(false, Ordering::SeqCst);
                slot.occupied = true;
                return Some(encode_server_id(TAG_SERIAL_RTU_SERVER, 0));
            }
            return None;
        }
        for (i, slot) in self.serial_rtu_slots.iter_mut().enumerate() {
            if !slot.occupied {
                slot.value = MaybeUninit::new(value);
                slot.borrow_flag.store(false, Ordering::SeqCst);
                slot.occupied = true;
                return Some(encode_server_id(TAG_SERIAL_RTU_SERVER, i));
            }
        }
        None
    }

    #[cfg(feature = "serial-ascii")]
    /// Allocate a Serial ASCII server in the pool and return its id.
    fn allocate_serial_ascii(&mut self, value: SerialAsciiServerInner) -> Option<MbusServerId> {
        if MAX_SERIAL_SERVERS == 1 {
            let slot = &mut self.serial_ascii_slots[0];
            if !slot.occupied {
                slot.value = MaybeUninit::new(value);
                slot.borrow_flag.store(false, Ordering::SeqCst);
                slot.occupied = true;
                return Some(encode_server_id(TAG_SERIAL_ASCII_SERVER, 0));
            }
            return None;
        }
        for (i, slot) in self.serial_ascii_slots.iter_mut().enumerate() {
            if !slot.occupied {
                slot.value = MaybeUninit::new(value);
                slot.borrow_flag.store(false, Ordering::SeqCst);
                slot.occupied = true;
                return Some(encode_server_id(TAG_SERIAL_ASCII_SERVER, i));
            }
        }
        None
    }

    /// Free the server slot identified by `id`.
    fn free(&mut self, id: MbusServerId) -> bool {
        let idx = server_id_index(id);
        match server_id_tag(id) {
            #[cfg(feature = "network-tcp")]
            TAG_TCP_SERVER => {
                if idx >= MAX_TCP_SERVERS {
                    return false;
                }
                let slot = if MAX_TCP_SERVERS == 1 {
                    &mut self.tcp_slots[0]
                } else {
                    &mut self.tcp_slots[idx]
                };
                if !slot.occupied {
                    return false;
                }
                unsafe { slot.value.assume_init_drop() };
                slot.borrow_flag.store(false, Ordering::SeqCst);
                slot.occupied = false;
                true
            }
            #[cfg(feature = "serial-rtu")]
            TAG_SERIAL_RTU_SERVER => {
                if idx >= MAX_SERIAL_SERVERS {
                    return false;
                }
                let slot = if MAX_SERIAL_SERVERS == 1 {
                    &mut self.serial_rtu_slots[0]
                } else {
                    &mut self.serial_rtu_slots[idx]
                };
                if !slot.occupied {
                    return false;
                }
                unsafe { slot.value.assume_init_drop() };
                slot.borrow_flag.store(false, Ordering::SeqCst);
                slot.occupied = false;
                true
            }
            #[cfg(feature = "serial-ascii")]
            TAG_SERIAL_ASCII_SERVER => {
                if idx >= MAX_SERIAL_SERVERS {
                    return false;
                }
                let slot = if MAX_SERIAL_SERVERS == 1 {
                    &mut self.serial_ascii_slots[0]
                } else {
                    &mut self.serial_ascii_slots[idx]
                };
                if !slot.occupied {
                    return false;
                }
                unsafe { slot.value.assume_init_drop() };
                slot.borrow_flag.store(false, Ordering::SeqCst);
                slot.occupied = false;
                true
            }
            _ => false,
        }
    }

    /// Check if the slot identified by `id` is currently occupied.
    fn is_occupied(&self, id: MbusServerId) -> bool {
        let idx = server_id_index(id);
        match server_id_tag(id) {
            #[cfg(feature = "network-tcp")]
            TAG_TCP_SERVER => {
                if MAX_TCP_SERVERS == 1 {
                    idx == 0 && self.tcp_slots[0].occupied
                } else {
                    idx < MAX_TCP_SERVERS && self.tcp_slots[idx].occupied
                }
            }
            #[cfg(feature = "serial-rtu")]
            TAG_SERIAL_RTU_SERVER => {
                if MAX_SERIAL_SERVERS == 1 {
                    idx == 0 && self.serial_rtu_slots[0].occupied
                } else {
                    idx < MAX_SERIAL_SERVERS && self.serial_rtu_slots[idx].occupied
                }
            }
            #[cfg(feature = "serial-ascii")]
            TAG_SERIAL_ASCII_SERVER => {
                if MAX_SERIAL_SERVERS == 1 {
                    idx == 0 && self.serial_ascii_slots[0].occupied
                } else {
                    idx < MAX_SERIAL_SERVERS && self.serial_ascii_slots[idx].occupied
                }
            }
            _ => false,
        }
    }
}

// ── Global static pool ────────────────────────────────────────────────────────

struct SyncServerPool(UnsafeCell<ServerPool>);
unsafe impl Sync for SyncServerPool {}

static SERVER_POOL: SyncServerPool = SyncServerPool(UnsafeCell::new(ServerPool::new()));

// ── Public pool operations ────────────────────────────────────────────────────

#[cfg(feature = "network-tcp")]
pub(super) fn server_pool_allocate_tcp(
    inner: TcpServerInner,
) -> Result<MbusServerId, MbusStatusCode> {
    let _guard = ServerPoolLockGuard::new();
    let pool = unsafe { &mut *SERVER_POOL.0.get() };
    pool.allocate_tcp(inner)
        .ok_or(MbusStatusCode::MbusErrPoolFull)
}

#[cfg(feature = "serial-rtu")]
pub(super) fn server_pool_allocate_serial_rtu(
    inner: SerialRtuServerInner,
) -> Result<MbusServerId, MbusStatusCode> {
    let _guard = ServerPoolLockGuard::new();
    let pool = unsafe { &mut *SERVER_POOL.0.get() };
    pool.allocate_serial_rtu(inner)
        .ok_or(MbusStatusCode::MbusErrPoolFull)
}

#[cfg(feature = "serial-ascii")]
pub(super) fn server_pool_allocate_serial_ascii(
    inner: SerialAsciiServerInner,
) -> Result<MbusServerId, MbusStatusCode> {
    let _guard = ServerPoolLockGuard::new();
    let pool = unsafe { &mut *SERVER_POOL.0.get() };
    pool.allocate_serial_ascii(inner)
        .ok_or(MbusStatusCode::MbusErrPoolFull)
}

pub(super) fn server_pool_free(id: MbusServerId) -> bool {
    let _server_guard = ServerLockGuard::new(id);
    let _pool_guard = ServerPoolLockGuard::new();
    let pool = unsafe { &mut *SERVER_POOL.0.get() };
    pool.free(id)
}

/// Borrow a TCP server and apply `f` to it.
#[cfg(feature = "network-tcp")]
pub(super) fn with_tcp_server<F, R>(id: MbusServerId, f: F) -> Result<R, MbusStatusCode>
where
    F: FnOnce(&mut TcpServerInner) -> R,
{
    if !is_tcp_server_id(id) {
        return Err(MbusStatusCode::MbusErrClientTypeMismatch);
    }

    let _guard = ServerLockGuard::new(id);
    let pool = unsafe { &mut *SERVER_POOL.0.get() };

    if !pool.is_occupied(id) {
        return Err(MbusStatusCode::MbusErrInvalidClientId);
    }

    let idx = server_id_index(id);
    let slot = if MAX_TCP_SERVERS == 1 {
        &mut pool.tcp_slots[0]
    } else {
        &mut pool.tcp_slots[idx]
    };
    if slot.borrow_flag.swap(true, Ordering::SeqCst) {
        return Err(MbusStatusCode::MbusErrBusy);
    }
    let _borrow = ServerBorrowGuard::new(&slot.borrow_flag);

    let inner = unsafe { slot.value.assume_init_mut() };
    Ok(f(inner))
}

/// Internal serial dispatch helper.
#[cfg(any(feature = "serial-rtu", feature = "serial-ascii"))]
macro_rules! dispatch_serial_server {
    ($id:expr, $pool:expr, $slots:ident, $f:expr) => {{
        let idx = server_id_index($id);
        let slot = if MAX_SERIAL_SERVERS == 1 {
            &mut $pool.$slots[0]
        } else {
            &mut $pool.$slots[idx]
        };
        if slot.borrow_flag.swap(true, Ordering::SeqCst) {
            return Err(MbusStatusCode::MbusErrBusy);
        }
        let _borrow = ServerBorrowGuard::new(&slot.borrow_flag);
        let inner = unsafe { slot.value.assume_init_mut() };
        Ok($f(inner))
    }};
}

#[cfg(all(feature = "serial-rtu", feature = "serial-ascii"))]
pub(super) fn with_serial_server<F1, F2, R>(
    id: MbusServerId,
    f_rtu: F1,
    f_ascii: F2,
) -> Result<R, MbusStatusCode>
where
    F1: FnOnce(&mut SerialRtuServerInner) -> R,
    F2: FnOnce(&mut SerialAsciiServerInner) -> R,
{
    if !is_serial_server_id(id) {
        return Err(MbusStatusCode::MbusErrClientTypeMismatch);
    }

    let _guard = ServerLockGuard::new(id);
    let pool = unsafe { &mut *SERVER_POOL.0.get() };

    if !pool.is_occupied(id) {
        return Err(MbusStatusCode::MbusErrInvalidClientId);
    }

    if is_serial_rtu_server_id(id) {
        dispatch_serial_server!(id, pool, serial_rtu_slots, f_rtu)
    } else {
        dispatch_serial_server!(id, pool, serial_ascii_slots, f_ascii)
    }
}

#[cfg(all(feature = "serial-rtu", not(feature = "serial-ascii")))]
pub(super) fn with_serial_server<F1, F2, R>(
    id: MbusServerId,
    f_rtu: F1,
    _f_ascii: F2,
) -> Result<R, MbusStatusCode>
where
    F1: FnOnce(&mut SerialRtuServerInner) -> R,
    F2: FnOnce(&mut SerialRtuServerInner) -> R,
{
    if !is_serial_server_id(id) {
        return Err(MbusStatusCode::MbusErrClientTypeMismatch);
    }

    let _guard = ServerLockGuard::new(id);
    let pool = unsafe { &mut *SERVER_POOL.0.get() };

    if !pool.is_occupied(id) {
        return Err(MbusStatusCode::MbusErrInvalidClientId);
    }

    dispatch_serial_server!(id, pool, serial_rtu_slots, f_rtu)
}

#[cfg(all(feature = "serial-ascii", not(feature = "serial-rtu")))]
pub(super) fn with_serial_server<F1, F2, R>(
    id: MbusServerId,
    f_rtu: F1,
    f_ascii: F2,
) -> Result<R, MbusStatusCode>
where
    F1: FnOnce(&mut SerialAsciiServerInner) -> R,
    F2: FnOnce(&mut SerialAsciiServerInner) -> R,
{
    if !is_serial_server_id(id) {
        return Err(MbusStatusCode::MbusErrClientTypeMismatch);
    }

    let _guard = ServerLockGuard::new(id);
    let pool = unsafe { &mut *SERVER_POOL.0.get() };

    if !pool.is_occupied(id) {
        return Err(MbusStatusCode::MbusErrInvalidClientId);
    }

    dispatch_serial_server!(id, pool, serial_ascii_slots, f_ascii)
}

/// Convenience macro to dispatch the same body to both serial variants.
#[cfg(any(feature = "serial-rtu", feature = "serial-ascii"))]
macro_rules! with_serial_server_uniform {
    ($id:expr, |$inner:ident| $body:expr) => {
        $crate::c::server::pool::with_serial_server($id, |$inner| $body, |$inner| $body)
    };
}
#[cfg(any(feature = "serial-rtu", feature = "serial-ascii"))]
pub(super) use with_serial_server_uniform;