Convert ParsedPacket into Data

This commit is contained in:
Joscha 2024-12-07 23:36:02 +01:00
parent 1bb043e10a
commit cbb668c9da

View file

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