mbus-ffi 0.16.0

Native C FFI and browser WASM bindings for modbus-rs client APIs, with optional generated server bindings
Documentation
//! WASM and Native C/C++ bindings for the Modbus workspace.
//!
//! Provides both WASM browser bindings and native C FFI bindings for the modbus-rs stack.
//!
//! Browser-facing APIs (feature `wasm`, `wasm32` target only):
//! - `WasmModbusClient` for WebSocket/TCP gateway usage
//! - `WasmSerialModbusClient` for Web Serial (RTU/ASCII)
//! - `request_serial_port` and `WasmSerialPortHandle` helpers
//! - `WasmServerBindingPlan` and `WasmServerTransportKind` (server binding design surface)
//!
//! Native C FFI — client (feature `c`, non-wasm targets):
//! - `mbus_tcp_client_new` / `mbus_serial_client_new` — create clients, return an ID
//! - `mbus_tcp_poll` / `mbus_serial_poll` — drive the request/response state machine
//! - Per-operation request functions (coils, registers, discrete inputs, etc.)
//! - Response data delivered via C function-pointer callbacks in `MbusCallbacks`
//!
//! Native C FFI — server (feature `c-server`, non-wasm targets):
//! There are two server integration approaches:
//!
//! **Approach 1 — hand-written handlers** (`c_server_demo`):
//! Wire FC callbacks directly in `main.c` via `mbus_tcp_server_new`.
//! No code generation required.
//!
//! **Approach 2 — YAML-driven codegen** (`c_server_demo_yaml`):
//! Declare the device register/coil map in a YAML file.  `build.rs` reads
//! `MBUS_SERVER_APP_CONFIG` at compile time and generates a type-safe Rust
//! dispatcher into `$OUT_DIR` (never tracked in git).  `gen-server-app` produces
//! the matching C header (`mbus_server_app.h`).
//!
//! ```text
//! MBUS_SERVER_APP_CONFIG=/path/to/server_app.yaml cargo build -p mbus-ffi --features c-server
//! ```
#![cfg_attr(all(not(doc), not(has_unwind), not(target_arch = "wasm32")), no_std)]
#![warn(missing_docs)]

#[cfg(all(not(doc), not(has_unwind), not(target_arch = "wasm32")))]
use core::panic::PanicInfo;

#[cfg(all(not(doc), not(has_unwind), not(target_arch = "wasm32")))]
#[panic_handler]
fn panic_handler(_info: &PanicInfo) -> ! {
    loop {}
}

// Pool configuration generated by build.rs from MBUS_MAX_TCP_CLIENTS and MBUS_MAX_SERIAL_CLIENTS env vars.
include!(concat!(env!("OUT_DIR"), "/pool_config.rs"));

#[cfg(all(
    target_arch = "wasm32",
    any(feature = "wasm-client", feature = "wasm-server")
))]
mod wasm;

#[cfg(all(target_arch = "wasm32", feature = "wasm-client"))]
pub use wasm::{WasmModbusClient, WasmWsTransport};

#[cfg(all(target_arch = "wasm32", feature = "wasm-client"))]
pub use wasm::{
    ModbusErrorCode, WasmAsciiTransport, WasmRtuTransport, WasmSerialModbusClient,
    WasmSerialPortHandle, get_modbus_error_code, request_serial_port,
};

#[cfg(all(target_arch = "wasm32", feature = "wasm-server"))]
pub use wasm::{
    WasmSerialServer, WasmSerialServerOptions, WasmServerTransportKind, WasmTcpServer,
    WasmTcpServerOptions,
};

#[allow(missing_docs)]
#[cfg(any(
    feature = "c-client",
    feature = "c-server",
    feature = "c-gateway",
    feature = "dotnet",
    feature = "go",
))]
pub mod c;

#[cfg(any(feature = "python-client", feature = "python-server"))]
#[allow(missing_docs)]
pub mod python;

#[cfg(all(feature = "dotnet", not(target_arch = "wasm32")))]
#[allow(missing_docs)]
pub mod dotnet;

#[cfg(all(feature = "go", not(target_arch = "wasm32")))]
#[allow(missing_docs)]
pub mod go;

#[cfg(all(
    any(
        feature = "nodejs-client",
        feature = "nodejs-server",
        feature = "nodejs-gateway"
    ),
    not(target_arch = "wasm32")
))]
#[allow(missing_docs)]
/// cbindgen:ignore
pub mod nodejs;