| 1 | use bytes::Bytes; |
| 2 | |
| 3 | use crate::error::Error; |
| 4 | |
| 5 | pub trait ProtocolDecode<'de, Context = ()> |
| 6 | where |
| 7 | Self: Sized, |
| 8 | { |
| 9 | fn decode(buf: Bytes) -> Result<Self, Error> |
| 10 | where |
| 11 | Self: ProtocolDecode<'de, ()>, |
| 12 | { |
| 13 | Self::decode_with(buf, ()) |
| 14 | } |
| 15 | |
| 16 | fn decode_with(buf: Bytes, context: Context) -> Result<Self, Error>; |
| 17 | } |
| 18 | |
| 19 | impl ProtocolDecode<'_> for Bytes { |
| 20 | fn decode_with(buf: Bytes, _: ()) -> Result<Self, Error> { |
| 21 | Ok(buf) |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | impl ProtocolDecode<'_> for () { |
| 26 | fn decode_with(_: Bytes, _: ()) -> Result<(), Error> { |
| 27 | Ok(()) |
| 28 | } |
| 29 | } |