ws-kit
Generic authenticated typed WebSocket toolkit for Rust — BroadcastHub, RoomManager, heartbeat, and token extraction for Axum.
Features
axum(default) — Axumws+tower,TokenExtractor::extract_token(&Parts, _)tracing— tracing instrumentation
Quick start
use ;
use ;
async
Rooms:
use RoomManager;
let m = new;
let room = m.get_or_create;
room.join;
room.broadcast.unwrap;
Token extraction:
use ;
let ex = default; // Bearer, ?token=, ?access_token=
let tok = ex.extract_from_parts;
Codec:
use Codec;
use ;
let m = Msg ;
let s = m.encode;
let d = decode.unwrap;
Concurrency testing
The connection counter's atomic logic (bounded increment CAS loop, saturating
decrement) is model-checked with loom under
--cfg loom — see src/loom_tests.rs:
RUSTFLAGS="--cfg loom"
(--no-default-features drops the axum stack — tokio-tungstenite does
not compile under --cfg loom; the models only need the counter.)
Loom exhaustively explores bounded interleavings and proves: balanced
increment/decrement pairs always return the count to zero, the count never
goes negative, and the connection limit is never exceeded under races.
What loom does not cover: tokio::sync::broadcast and DashMap
internals (not loom-compatible) — those are trusted via tokio's and
dashmap's own concurrency testing.