|
2 | 2 | //! and [`DisconnectHandler`](super::DisconnectHandler).
|
3 | 3 | //!
|
4 | 4 | //! They can be used to extract data from the context of the handler and get specific params. Here are some examples of extractors:
|
5 |
| -//! * [`Data`]: extracts and deserialize to json any data, if a deserialization error occurs the handler won't be called: |
| 5 | +//! * [`Data`]: extracts and deserialize to json any data. Because it consumes the event it should be the last argument. If a |
| 6 | +//! deserialization error occurs the handler won't be called: |
6 | 7 | //! - for [`ConnectHandler`](super::ConnectHandler): extracts and deserialize to json the auth data
|
7 | 8 | //! - for [`MessageHandler`](super::MessageHandler): extracts and deserialize to json the message data
|
8 |
| -//! * [`TryData`]: extracts and deserialize to json any data but with a `Result` type in case of error: |
| 9 | +//! * [`TryData`]: extracts and deserialize to json any data. Because it consumes the event it should be the last argument. In case of |
| 10 | +//! error, a `Result` type is returned; |
9 | 11 | //! - for [`ConnectHandler`](super::ConnectHandler): extracts and deserialize to json the auth data
|
10 | 12 | //! - for [`MessageHandler`](super::MessageHandler): extracts and deserialize to json the message data
|
11 | 13 | //! * [`SocketRef`]: extracts a reference to the [`Socket`]
|
12 |
| -//! * [`Bin`]: extract a binary payload for a given message. Because it consumes the event it should be the last argument |
| 14 | +//! * [`Bin`]: extract a binary payload for a given message. |
13 | 15 | //! * [`AckSender`]: Can be used to send an ack response to the current message event
|
14 | 16 | //! * [`ProtocolVersion`](crate::ProtocolVersion): extracts the protocol version
|
15 | 17 | //! * [`TransportType`](crate::TransportType): extracts the transport type
|
@@ -129,19 +131,19 @@ where
|
129 | 131 | .map(Data)
|
130 | 132 | }
|
131 | 133 | }
|
132 |
| -impl<T, A> FromMessageParts<A> for Data<T> |
| 134 | +impl<T, A> FromMessage<A> for Data<T> |
133 | 135 | where
|
134 | 136 | T: DeserializeOwned,
|
135 | 137 | A: Adapter,
|
136 | 138 | {
|
137 | 139 | type Error = serde_json::Error;
|
138 |
| - fn from_message_parts( |
139 |
| - _: &Arc<Socket<A>>, |
140 |
| - v: &mut PayloadValue, |
141 |
| - _: &Option<i64>, |
| 140 | + fn from_message( |
| 141 | + _: Arc<Socket<A>>, |
| 142 | + mut v: PayloadValue, |
| 143 | + _: Option<i64>, |
142 | 144 | ) -> Result<Self, Self::Error> {
|
143 |
| - upwrap_array(v); |
144 |
| - v.clone().into_data::<T>().map(Data) |
| 145 | + upwrap_array(&mut v); |
| 146 | + v.into_data::<T>().map(Data) |
145 | 147 | }
|
146 | 148 | }
|
147 | 149 |
|
@@ -237,14 +239,18 @@ impl<A: Adapter> SocketRef<A> {
|
237 | 239 | /// An Extractor that returns the binary data of the message.
|
238 | 240 | /// If there is no binary data, it will contain an empty vec.
|
239 | 241 | pub struct Bin(pub Vec<Vec<u8>>);
|
240 |
| -impl<A: Adapter> FromMessage<A> for Bin { |
| 242 | +impl<A: Adapter> FromMessageParts<A> for Bin { |
241 | 243 | type Error = Infallible;
|
242 |
| - fn from_message( |
243 |
| - _: Arc<Socket<A>>, |
244 |
| - mut v: PayloadValue, |
245 |
| - _: Option<i64>, |
| 244 | + fn from_message_parts( |
| 245 | + _: &Arc<Socket<A>>, |
| 246 | + v: &mut PayloadValue, |
| 247 | + _: &Option<i64>, |
246 | 248 | ) -> Result<Self, Infallible> {
|
247 |
| - Ok(Bin(v.extract_binary_payloads())) |
| 249 | + Ok(Bin(v |
| 250 | + .binary_payloads_ref() |
| 251 | + .into_iter() |
| 252 | + .map(Clone::clone) |
| 253 | + .collect())) |
248 | 254 | }
|
249 | 255 | }
|
250 | 256 |
|
|
0 commit comments