Rust transport — what changed and what to watch
Starting in Whixp 3.1.0, the low-level connection, TLS, WebSocket, retry, and stanza framing moved from Dart to an optional Rust transport loaded via FFI. This page explains what you should pay attention to when using Whixp from that version onward.
What moved to Rust
- In Rust: TCP connect, TLS (DirectTLS and StartTLS via rustls), WebSocket (
ws:///wss://), connection retry, handshake error handling, and splitting the byte stream into XML stanzas. - Still in Dart: DNS resolution, high-level API (handlers, events, send queue, batching, rate limiting), and everything above the transport (stanza handling, sessions, etc.).
So: transport and framing live in Rust when the native library is present; the rest of Whixp is unchanged.
When the native lib is used
- If the native library is found on the current platform,
Transportuses it. You do not need to import a special entrypoint for normal use; the defaultWhixp/Transportpath uses the Rust transport when available. - If the library is not found,
Transportconstruction throws with a clear message (e.g. you must build or add the binary for your OS — see Native binaries per platform).
So: users must have the correct native binary for their OS if they want the Rust transport. No binary ⇒ no Rust path; the error at construction time tells you.
What to pay attention to
-
Binaries per platform
Each OS expects the built library in a specific place (e.g.macos/,linux/,windows/, Android jniLibs, iOS). If you ship or run on multiple platforms, ensure the right binary is present for each. See Native binaries per platform. -
Testing
Underdart test, the native lib is not loaded by default (to avoid process kill from loading the dylib in test isolates). So normaldart testormake testdoes not exercise the Rust transport. To run Transport tests with the native lib:WHIXP_TEST_NATIVE=1 dart test test/transport_test.dartIf the process is killed, try more heap:
DART_VM_OPTIONS="--old_gen_heap_size=2048" WHIXP_TEST_NATIVE=1 dart test test/transport_test.dart -
Graceful disconnect (3.2.0+)
On server down or connection termination, the transport tears down the native handle, emitsTransportState.disconnectedonce, and cleans up so the app can reconnect. No special action required; just handledisconnectedas before. -
Optional entrypoint
If you want to depend explicitly on the native layer (e.g. for tree-shaking or clarity), you can importpackage:whixp/whixp_native.dart. For typical use, the defaultpackage:whixp/whixp.dartpath is enough; it will use the Rust transport when the library is available. -
WebSocket
Rust handles WebSocket. UseuseWebSocket: trueand optionalwsPath(e.g."/ws") onTransport/Whixpas documented.
Summary
- Version: Rust transport from 3.1.0; improvements (XCFramework, graceful disconnect, release profile) in 3.2.0 / 3.3.0.
- User responsibility: Provide the correct native binary for each OS you target (or use a package/release that already includes them).
- Tests: Use
WHIXP_TEST_NATIVE=1when you want to run Transport tests with the native lib.
For exact file names and paths per OS, see Native binaries per platform.