Convert ParsedPacket into Data
This commit is contained in:
parent
28c1ce243e
commit
11bb32d53e
1 changed files with 14 additions and 0 deletions
|
|
@ -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<Data> {
|
||||
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<ParsedPacket> for Packet {
|
|||
value.into_packet()
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<ParsedPacket> for Data {
|
||||
type Error = Error;
|
||||
|
||||
fn try_from(value: ParsedPacket) -> Result<Self, Self::Error> {
|
||||
value.into_data()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue