diff --git a/src/api/packets.rs b/src/api/packets.rs index 210ddc5..e269b9e 100644 --- a/src/api/packets.rs +++ b/src/api/packets.rs @@ -5,6 +5,8 @@ use serde::{Deserialize, Serialize}; use serde_json::Value; +use crate::error::{self, Error}; + use super::PacketType; /// A "raw" packet. @@ -227,6 +229,10 @@ impl ParsedPacket { } } + pub fn into_data(self) -> error::Result { + self.content.map_err(Error::Euph) + } + /// Convert a [`Packet`] into a [`ParsedPacket`]. /// /// This method may fail if the packet data is invalid. @@ -303,3 +309,11 @@ impl TryFrom for Packet { value.into_packet() } } + +impl TryFrom for Data { + type Error = Error; + + fn try_from(value: ParsedPacket) -> Result { + value.into_data() + } +}