diff options
author | Wiktor Kwapisiewicz <wiktor@metacode.biz> | 2020-04-01 15:29:35 +0200 |
---|---|---|
committer | Wiktor Kwapisiewicz <wiktor@metacode.biz> | 2020-04-03 14:22:38 +0200 |
commit | 73a7597cbd934d4db170aac313775d63b465ae5f (patch) | |
tree | 7d0abdf74697ca6f4ee022fbebfbf1acf47f5d18 | |
parent | 49315e0b3df7793d6f35901e77ab76341a7f3770 (diff) |
openpgp: Convert `PacketPile::from_packet_parser` to `TryFrom<PacketParserResult>`
-rw-r--r-- | openpgp/src/packet_pile.rs | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/openpgp/src/packet_pile.rs b/openpgp/src/packet_pile.rs index 19cd892b..3811cb7d 100644 --- a/openpgp/src/packet_pile.rs +++ b/openpgp/src/packet_pile.rs @@ -1,3 +1,4 @@ +use std::convert::TryFrom; use std::fmt; use std::slice; use std::vec; @@ -312,12 +313,16 @@ impl PacketPile { .buffer_unread_content() .into_packet_pile() } +} + +impl<'a> TryFrom<PacketParserResult<'a>> for PacketPile { + type Error = anyhow::Error; /// Reads all of the packets from a `PacketParser`, and turns them /// into a message. /// /// Note: this assumes that `ppr` points to a top-level packet. - pub fn from_packet_parser<'a>(ppr: PacketParserResult<'a>) + fn try_from(ppr: PacketParserResult<'a>) -> Result<PacketPile> { // Things are not going to work out if we don't start with a @@ -440,10 +445,10 @@ impl<'a> PacketParserBuilder<'a> { /// # } /// ``` pub fn into_packet_pile(self) -> Result<PacketPile> { - PacketPile::from_packet_parser(self.finalize()?) + PacketPile::try_from(self.finalize()?) } } - + #[cfg(test)] mod test { use super::*; |