Skip to main content

musli_web/
lib.rs

1//! [<img alt="github" src="https://img.shields.io/badge/github-udoprog/musli-8da0cb?style=for-the-badge&logo=github" height="20">](https://github.com/udoprog/musli)
2//! [<img alt="crates.io" src="https://img.shields.io/crates/v/musli-web.svg?style=for-the-badge&color=fc8d62&logo=rust" height="20">](https://crates.io/crates/musli-web)
3//! [<img alt="docs.rs" src="https://img.shields.io/badge/docs.rs-musli--web-66c2a5?style=for-the-badge&logoColor=white&logo=data:image/svg+xml;base64,PHN2ZyByb2xlPSJpbWciIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgdmlld0JveD0iMCAwIDUxMiA1MTIiPjxwYXRoIGZpbGw9IiNmNWY1ZjUiIGQ9Ik00ODguNiAyNTAuMkwzOTIgMjE0VjEwNS41YzAtMTUtOS4zLTI4LjQtMjMuNC0zMy43bC0xMDAtMzcuNWMtOC4xLTMuMS0xNy4xLTMuMS0yNS4zIDBsLTEwMCAzNy41Yy0xNC4xIDUuMy0yMy40IDE4LjctMjMuNCAzMy43VjIxNGwtOTYuNiAzNi4yQzkuMyAyNTUuNSAwIDI2OC45IDAgMjgzLjlWMzk0YzAgMTMuNiA3LjcgMjYuMSAxOS45IDMyLjJsMTAwIDUwYzEwLjEgNS4xIDIyLjEgNS4xIDMyLjIgMGwxMDMuOS01MiAxMDMuOSA1MmMxMC4xIDUuMSAyMi4xIDUuMSAzMi4yIDBsMTAwLTUwYzEyLjItNi4xIDE5LjktMTguNiAxOS45LTMyLjJWMjgzLjljMC0xNS05LjMtMjguNC0yMy40LTMzLjd6TTM1OCAyMTQuOGwtODUgMzEuOXYtNjguMmw4NS0zN3Y3My4zek0xNTQgMTA0LjFsMTAyLTM4LjIgMTAyIDM4LjJ2LjZsLTEwMiA0MS40LTEwMi00MS40di0uNnptODQgMjkxLjFsLTg1IDQyLjV2LTc5LjFsODUtMzguOHY3NS40em0wLTExMmwtMTAyIDQxLjQtMTAyLTQxLjR2LS42bDEwMi0zOC4yIDEwMiAzOC4ydi42em0yNDAgMTEybC04NSA0Mi41di03OS4xbDg1LTM4Ljh2NzUuNHptMC0xMTJsLTEwMiA0MS40LTEwMi00MS40di0uNmwxMDItMzguMiAxMDIgMzguMnYuNnoiPjwvcGF0aD48L3N2Zz4K" height="20">](https://docs.rs/musli-web)
4//!
5//! This crate provides a set of utilities for working with various web-based
6//! APIs and [Müsli].
7//!
8//! It includes support for:
9//! - [`axum`] [`Json`] integration, allowing you to use Müsli for serialization
10//!   and deserialization in your Axum applications.
11//! - [`axum`] [`ws::Server`] integration, allowing you to build the server side
12//!   of the websocket protocol this crate implements.
13//! - [`yew`] integration, allowing you to use Müsli for communicating with
14//!   websocket clients using a well-defined API.
15//! - [`tokio-tungstenite`] integration through [`tungstenite029`], allowing
16//!   non-browser clients to talk to the same websocket API.
17//!
18//! Note that the organization of the modules include the version of the corresponding
19//! crate. Unstable versions are prefixed with `0`, such as [`yew023`].
20//!
21//! See the following modules for how to use:
22//! * [`axum08`] for [`axum`] `0.8.x` integration.
23//! * [`tungstenite029`] for [`tokio-tungstenite`] `0.29.x` integration.
24//! * [`yew022`] for [`yew`] `0.22.x` integration.
25//! * [`yew023`] for [`yew`] `0.23.x` integration.
26//! * [`web03`] for [`web-sys`] `0.3.x` integration.
27//!
28//! <br>
29//!
30//! ## Features
31//!
32//! * A wasm-compatible and convenient websocket protocol with support for
33//!   request-reply and broadcasts.
34//! * [Channel support] allowing the server to identify the source of a message
35//!   and clients to correlate messages.
36//! * A [negotiable body format], so a client can pick how much schema evolution
37//!   it needs and the server adapts to it. Message envelopes use a fixed
38//!   encoding so negotiation itself never depends on the outcome.
39//!
40//! The available formats, from most compact to most capable, are
41//! [`Format::Packed`], [`Format::Storage`], [`Format::Wire`] (the default, and
42//! the least capable one which is fully upgrade safe), [`Format::Descriptive`]
43//! and [`Format::Json`]. Each is gated behind a `format-*` feature.
44//!
45//! [Channel support]: https://docs.rs/musli-web/latest/musli_web/web/struct.Handle.html#method.channel
46//! [negotiable body format]: https://docs.rs/musli-web/latest/musli_web/api/index.html#wire-format
47//!
48//! <br>
49//!
50//! ## Examples
51//!
52//! * [`api`] is the example crate which defines API types shared between server
53//!   and client.
54//! * [`server`] is the axum-based server implementation.
55//! * [`client`] is the yew client communicating with the server.
56//!
57//! You can run the client like this:
58//!
59//! ```sh
60//! cd examples/client && trunk serve
61//! ```
62//!
63//! You can run the server like this:
64//!
65//! ```sh
66//! cd examples/server && cargo run
67//! ```
68//!
69//! [`api`]: <https://github.com/udoprog/musli/tree/main/crates/musli-web/examples/api/>
70//! [`axum`]: <https://docs.rs/axum>
71//! [`client`]: <https://github.com/udoprog/musli/tree/main/crates/musli-web/examples/client/>
72//! [`Json`]: <https://docs.rs/musli-web/latest/musli-web/Json.struct.html>
73//! [`server`]: <https://github.com/udoprog/musli/tree/main/crates/musli-web/examples/server/>
74//! [`tokio-tungstenite`]: <https://docs.rs/tokio-tungstenite>
75//! [`web-sys`]: <https://docs.rs/web-sys>
76//! [`ws::Server`]: <https://docs.rs/musli-web/latest/musli_web/ws/struct.Server.html>
77//! [`yew`]: <https://yew.rs>
78//! [Müsli]: <https://github.com/udoprog/musli>
79
80#![no_std]
81#![cfg_attr(doc_cfg, feature(doc_cfg))]
82#![allow(clippy::type_complexity)]
83
84#[cfg(feature = "std")]
85extern crate std;
86
87#[cfg(feature = "alloc")]
88extern crate alloc;
89
90#[cfg(feature = "axum08")]
91mod buf;
92#[cfg(feature = "axum08")]
93use self::buf::Buf;
94
95#[cfg(all(feature = "json", feature = "alloc"))]
96mod json;
97#[cfg(all(feature = "json", feature = "alloc"))]
98#[cfg_attr(doc_cfg, doc(cfg(all(feature = "json", feature = "alloc"))))]
99pub use self::json::Json;
100
101#[cfg(feature = "api")]
102#[cfg_attr(doc_cfg, doc(cfg(feature = "api")))]
103pub mod api;
104#[doc(inline)]
105#[cfg(feature = "api")]
106#[cfg_attr(doc_cfg, doc(cfg(feature = "api")))]
107pub use self::api::{AtomicChannelId, ChannelId, Format};
108
109#[cfg(feature = "api")]
110#[cfg_attr(doc_cfg, doc(cfg(feature = "api")))]
111pub mod format;
112
113#[cfg(feature = "axum08")]
114#[cfg_attr(doc_cfg, doc(cfg(feature = "axum08")))]
115pub mod axum08;
116
117#[cfg(feature = "client")]
118#[cfg_attr(doc_cfg, doc(cfg(feature = "client")))]
119pub mod client;
120
121#[cfg(feature = "tungstenite029")]
122#[cfg_attr(doc_cfg, doc(cfg(feature = "tungstenite029")))]
123pub mod tungstenite029;
124
125#[cfg(feature = "web03")]
126#[cfg_attr(doc_cfg, doc(cfg(feature = "web03")))]
127pub mod web;
128
129#[cfg(feature = "web03")]
130#[cfg_attr(doc_cfg, doc(cfg(feature = "web03")))]
131pub mod web03;
132
133#[cfg(feature = "yew022")]
134#[cfg_attr(doc_cfg, doc(cfg(feature = "yew022")))]
135pub mod yew022;
136
137#[cfg(feature = "yew023")]
138#[cfg_attr(doc_cfg, doc(cfg(feature = "yew023")))]
139pub mod yew023;
140
141#[cfg(any(feature = "yew022", feature = "yew023"))]
142mod implicit_clone06;
143
144#[cfg(feature = "ws")]
145#[cfg_attr(doc_cfg, doc(cfg(feature = "ws")))]
146pub mod ws;
147
148#[doc(hidden)]
149pub mod __macros {
150    pub use core::fmt;
151}