mqtt_typed_client/lib.rs
1//! # MQTT Typed Client
2//!
3#![doc = include_str!(concat!(env!("OUT_DIR"), "/generated/README.doc.md"))]
4//!
5//! ## API Reference
6//!
7//! Key traits and modules:
8//! - [`MessageSerializer`] - Custom serialization trait
9//! - [`prelude`] - Convenient imports for common use cases
10//! - [`info`] - Library metadata and version info
11//!
12//! ## See Also
13//!
14//! - [`crate::comparison`] - Detailed comparison with rumqttc
15//! - [`crate::examples`] - Complete usage examples with source code
16
17pub use mqtt_typed_client_core::*;
18#[cfg(feature = "macros")]
19pub use mqtt_typed_client_macros::*;
20
21pub mod prelude {
22 //! Convenient imports for common use cases
23
24 pub use mqtt_typed_client_core::structured::*;
25 pub use mqtt_typed_client_core::{
26 BincodeSerializer, ClientSettings, MessageSerializer, MqttClient,
27 MqttClientConfig, MqttClientError, MqttConnection, MqttOptions,
28 MqttPublisher, MqttSubscriber, QoS, Result, SubscriptionBuilder,
29 TypedLastWill,
30 };
31 #[cfg(feature = "macros")]
32 pub use mqtt_typed_client_macros::*;
33}
34
35pub mod comparison {
36 //! Detailed comparison with rumqttc
37 //!
38 //! This module provides comprehensive side-by-side comparison
39 //! between mqtt-typed-client and the underlying rumqttc library.
40 //!
41 #![doc = include_str!("../docs/COMPARISON_WITH_RUMQTTC.md")]
42}
43
44pub mod examples {
45 //! Complete usage examples with source code
46 //!
47 //! This module contains comprehensive examples demonstrating
48 //! various features and use cases of mqtt-typed-client.
49 //!
50 #![doc = include_str!(concat!(env!("OUT_DIR"), "/generated/examples.README.doc.md"))]
51
52 pub mod example_000_hello_world {
53 //! # Hello World Example
54 //!
55 //! Basic publish/subscribe with macros - demonstrates the core functionality
56 //! of mqtt-typed-client with type-safe topic handling.
57 //!
58 //! ## Usage
59 //! ```bash
60 //! cargo run --example 000_hello_world
61 //! ```
62 //!
63 //! ## Source Code
64 //!
65 //! ```ignore
66 #![doc = include_str!("../examples/000_hello_world.rs")]
67 //! ```
68 }
69
70 pub mod example_001_ping_pong {
71 //! # Ping Pong Example
72 //!
73 //! Multi-client communication demonstrating bidirectional message exchange
74 //! and concurrent MQTT operations.
75 //!
76 //! ## Usage
77 //! ```bash
78 //! cargo run --example 001_ping_pong
79 //! ```
80 //!
81 //! ## Source Code
82 //!
83 //! ```ignore
84 #![doc = include_str!("../examples/001_ping_pong.rs")]
85 //! ```
86 }
87
88 pub mod example_002_configuration {
89 //! # Configuration Example
90 //!
91 //! Advanced client configuration showing how to customize MQTT settings,
92 //! QoS levels, and connection parameters.
93 //!
94 //! ## Usage
95 //! ```bash
96 //! cargo run --example 002_configuration
97 //! ```
98 //!
99 //! ## Source Code
100 //!
101 //! ```ignore
102 #![doc = include_str!("../examples/002_configuration.rs")]
103 //! ```
104 }
105
106 pub mod example_003_hello_world_lwt {
107 //! # Last Will & Testament Example
108 //!
109 //! Demonstrates MQTT Last Will & Testament functionality for handling
110 //! unexpected client disconnections.
111 //!
112 //! ## Usage
113 //! ```bash
114 //! # Terminal 1: Start subscriber
115 //! cargo run --example 003_hello_world_lwt
116 //!
117 //! # Terminal 2: Run publisher (sends message then crashes)
118 //! cargo run --example 003_hello_world_lwt -- --publisher
119 //! ```
120 //!
121 //! ## Source Code
122 //!
123 //! ```ignore
124 #![doc = include_str!("../examples/003_hello_world_lwt.rs")]
125 //! ```
126 }
127
128 pub mod example_004_hello_world_tls {
129 //! # TLS/SSL Connections Example
130 //!
131 //! Secure MQTT connections using TLS/SSL with custom certificate handling
132 //! for development and production environments.
133 //!
134 //! ## Usage
135 //! ```bash
136 //! cargo run --example 004_hello_world_tls
137 //! ```
138 //!
139 //! ## Source Code
140 //!
141 //! ```ignore
142 #![doc = include_str!("../examples/004_hello_world_tls.rs")]
143 //! ```
144 }
145
146 pub mod example_005_hello_world_serializers {
147 //! # Custom Serializers Example
148 //!
149 //! Demonstrates how to implement and use custom message serializers
150 //! beyond the built-in formats.
151 //!
152 //! ## Usage
153 //! ```bash
154 //! cargo run --example 005_hello_world_serializers
155 //! ```
156 //!
157 //! ## Source Code
158 //!
159 //! ```ignore
160 #![doc = include_str!("../examples/005_hello_world_serializers.rs")]
161 //! ```
162 }
163
164 pub mod example_006_retain_and_clear {
165 //! # Retained Messages Example
166 //!
167 //! MQTT retained message functionality with multiple clients connecting
168 //! at different times to showcase broker message persistence.
169 //!
170 //! ## Usage
171 //! ```bash
172 //! cargo run --example 006_retain_and_clear
173 //! ```
174 //!
175 //! ## Source Code
176 //!
177 //! ```ignore
178 #![doc = include_str!("../examples/006_retain_and_clear.rs")]
179 //! ```
180 }
181
182 pub mod example_007_custom_patterns {
183 //! # Custom Topic Patterns Example
184 //!
185 //! Advanced topic pattern usage showing how to override default patterns
186 //! for environment-specific routing and multi-tenant applications.
187 //!
188 //! ## Usage
189 //! ```bash
190 //! cargo run --example 007_custom_patterns
191 //! ```
192 //!
193 //! ## Source Code
194 //!
195 //! ```ignore
196 #![doc = include_str!("../examples/007_custom_patterns.rs")]
197 //! ```
198 }
199
200 pub mod example_008_modular_example {
201 //! # Modular Application Structure Example
202 //!
203 //! Production-ready application structure showing how to organize
204 //! MQTT applications with multiple modules and clean separation of concerns.
205 //!
206 //! ## Usage
207 //! ```bash
208 //! cargo run --example 008_modular_example
209 //! ```
210 //!
211 //! ## Source Code
212 //!
213 //! ```ignore
214 #![doc = include_str!("../examples/008_modular_example.rs")]
215 //! ```
216 }
217
218 pub mod example_100_all_serializers_demo {
219 //! # Complete Serializer Test Suite
220 //!
221 //! Comprehensive example testing all 8 available serializers
222 //! with full publish/subscribe verification.
223 //!
224 //! ## Usage
225 //! ```bash
226 //! cargo run --example 100_all_serializers_demo --all-features
227 //! ```
228 //!
229 //! ## Source Code
230 //!
231 //! ```ignore
232 #![doc = include_str!("../examples/100_all_serializers_demo.rs")]
233 //! ```
234 }
235}
236
237pub const VERSION: &str = env!("CARGO_PKG_VERSION");
238
239pub mod info {
240 //! Library metadata and version information
241
242 pub const NAME: &str = env!("CARGO_PKG_NAME");
243 pub const VERSION: &str = env!("CARGO_PKG_VERSION");
244 pub const AUTHORS: &str = env!("CARGO_PKG_AUTHORS");
245 pub const DESCRIPTION: &str = env!("CARGO_PKG_DESCRIPTION");
246 pub const REPOSITORY: &str = env!("CARGO_PKG_REPOSITORY");
247 pub const HAS_MACROS: bool = cfg!(feature = "macros");
248
249 /// Returns a formatted version string with feature information
250 pub fn version_string() -> String {
251 if HAS_MACROS {
252 format!("{VERSION} (with macros)")
253 } else {
254 format!("{VERSION} (core only)")
255 }
256 }
257}
258
259#[cfg(test)]
260mod tests {
261 use super::*;
262
263 #[test]
264 fn test_version_is_valid() {
265 assert!(VERSION.chars().next().unwrap().is_ascii_digit());
266 }
267
268 #[test]
269 fn test_info_module() {
270 assert_eq!(info::VERSION, VERSION);
271 assert!(!info::version_string().is_empty());
272 }
273
274 #[cfg(feature = "macros")]
275 #[test]
276 fn test_macros_feature_enabled() {
277 assert!(info::HAS_MACROS);
278 assert!(info::version_string().contains("with macros"));
279 }
280
281 #[cfg(not(feature = "macros"))]
282 #[test]
283 fn test_macros_feature_disabled() {
284 assert!(!info::HAS_MACROS);
285 assert!(info::version_string().contains("core only"));
286 }
287}
288
289#[cfg(feature = "macros")]
290#[doc = ""]
291#[doc = "## Procedural Macros"]
292#[doc = ""]
293#[doc = "This build includes procedural macros for enhanced type safety and \
294 code generation."]
295#[doc = "See the `mqtt_typed_client_macros` documentation for detailed macro \
296 usage."]
297pub mod _macro_docs {}
298
299#[cfg(not(feature = "macros"))]
300#[doc = ""]
301#[doc = "## Core Only Build"]
302#[doc = ""]
303#[doc = "This build does not include procedural macros. To enable macros, add \
304 the 'macros' feature:"]
305#[doc = "```toml"]
306#[doc = "[dependencies]"]
307#[doc = "mqtt-typed-client = { version = \"0.1\", features = [\"macros\"] }"]
308#[doc = "```"]
309pub mod _core_only_docs {}