Skip to content

Commit 6ad87c4

Browse files
authored
doc(socketio): improve extractor docs (#382)
1 parent 87fd00a commit 6ad87c4

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

crates/socketioxide-core/src/lib.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ pub use engineioxide::{sid::Sid, Str};
4141

4242
/// Represents a value that can be sent over the engine.io wire as an engine.io packet
4343
/// or the data that can be outputed by a binary parser (e.g. [`MsgPackParser`](../socketioxide_parser_msgpack/index.html))
44-
/// or a string parser (e.g. [`CommonParser`](../socketioxide_parser_common/index.html)))
44+
/// or a string parser (e.g. [`CommonParser`](../socketioxide_parser_common/index.html))).
45+
///
46+
/// If you want to deserialize this value to a specific type. You should manually call the `Data` extractor.
4547
#[derive(Debug, Clone, PartialEq)]
4648
pub enum Value {
4749
/// A string payload that will be sent as a string engine.io packet.

crates/socketioxide/src/extract/mod.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
//! ### Extractors for [`ConnectHandler`], [`ConnectMiddleware`], [`MessageHandler`] and [`DisconnectHandler`](crate::handler::DisconnectHandler).
1+
//! ### Extractors for [`ConnectHandler`], [`ConnectMiddleware`],
2+
//! [`MessageHandler`] and [`DisconnectHandler`](crate::handler::DisconnectHandler).
23
//!
34
//! They can be used to extract data from the context of the handler and get specific params. Here are some examples of extractors:
45
//! * [`Data`]: extracts and deserialize from any receieved data, if a deserialization error occurs the handler won't be called:
@@ -22,9 +23,13 @@
2223
//! (Similar to axum's [`extract::Extension`](https://docs.rs/axum/latest/axum/struct.Extension.html)
2324
//! * [`MaybeHttpExtension`]: extracts an http extension of the given type if it exists or [`None`] otherwise.
2425
//!
25-
//! ### You can also implement your own Extractor with the [`FromConnectParts`], [`FromMessageParts`] and [`FromDisconnectParts`] traits
26-
//! When implementing these traits, if you clone the [`Arc<Socket>`](crate::socket::Socket) make sure that it is dropped at least when the socket is disconnected.
27-
//! Otherwise it will create a memory leak. It is why the [`SocketRef`] extractor is used instead of cloning the socket for common usage.
26+
//! ### You can also implement your own Extractor with the [`FromConnectParts`], [`FromMessageParts`] and
27+
//! [`FromDisconnectParts`] traits
28+
//! When implementing these traits, if you clone the [`Arc<Socket>`](crate::socket::Socket) make sure
29+
//! that it is dropped at least when the socket is disconnected.
30+
//! Otherwise it will create a memory leak. It is why the [`SocketRef`] extractor is used instead of cloning
31+
//! the socket for common usage.
32+
//! If you want to deserialize the [`Value`] data you must manually call the `Data` extractor to deserialize it.
2833
//!
2934
//! [`FromConnectParts`]: crate::handler::FromConnectParts
3035
//! [`FromMessageParts`]: crate::handler::FromMessageParts

crates/socketioxide/src/handler/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ pub(crate) use disconnect::BoxedDisconnectHandler;
1111
pub use disconnect::{DisconnectHandler, FromDisconnectParts};
1212
pub(crate) use message::BoxedMessageHandler;
1313
pub use message::{FromMessage, FromMessageParts, MessageHandler};
14+
pub use socketioxide_core::Value;
15+
1416
/// A struct used to erase the type of a [`ConnectHandler`] or [`MessageHandler`] so it can be stored in a map
1517
pub(crate) struct MakeErasedHandler<H, A, T> {
1618
handler: H,

0 commit comments

Comments
 (0)