From 11bb32d53e3c5b45bc10495f76a4d4bdc80381e8 Mon Sep 17 00:00:00 2001 From: Joscha Date: Sat, 7 Dec 2024 23:36:02 +0100 Subject: [PATCH] Convert ParsedPacket into Data --- src/api/packets.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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() + } +}