Injoint-rs
Injoint is a library for creating and managing WebSocket connections in declarative, inspired by state reducer approach.
About Injoint
Core concept of injoint is Joint structure - a wrapper for all multithreaded asynchronous functionality
that is necessary to run a WebSocket server. It is responsible for managing the state of the application,
handling incoming messages, and dispatching them to the appropriate reducers for each room individually.
Joint implementations
Joint structure is heuristically abstract and need to be implemented around some real-life conception,
for example, websockets or mpsc. injoint library currently provides these implementations for AbstractJoint:
WebsocketJoint- common implementation around asynchronous websocket connection usingtokioandtungstenitelibraries.AxumWSJoint- another implementation around websocket that can be integrated intoaxumrouter.MPSCJoint- implementation aroundtokio::sync::mpscchannels.
Usage
To use injoint, add this to your Cargo.toml:
[]
= "0.1.0"
Example of minimalistic websocket chat server:
use ;
use WebsocketJoint;
use Serialize;
use HashMap;
// message struct, used in State
// chat state struct
// state reducer, statically injected to `WebsocketJoint`
// using `reducer_actions` macro to generate boilerplate
// code implementing actions and their dispatching
async