From c9ee0ac8d7689aca241b9b117749a6faf4923676 Mon Sep 17 00:00:00 2001 From: "Neal H. Walfield" Date: Mon, 2 Jul 2018 11:00:00 +0200 Subject: openpgp: Create a special Option-like type for PacketParser. - In the future, we want to return some summary information about a parsed packet sequence after the packet sequence is fully parsed. Currently, PacketParser::next() and PacketParser::recurse() consume the PacketParser and return None on EOF. Thus, even if the summary information were stored in the PacketParser, it becomes inaccessible on EOF. - This change introduces a new type, PacketParserResult, that contains either a PacketParser or a PacketParserEOF. PacketParserEOF is returned on EOF instead of None. Since it is a struct, it can hold only any information that we want to return to the caller. --- openpgp/examples/statistics.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'openpgp/examples/statistics.rs') diff --git a/openpgp/examples/statistics.rs b/openpgp/examples/statistics.rs index 27cdc946..a5d75dda 100644 --- a/openpgp/examples/statistics.rs +++ b/openpgp/examples/statistics.rs @@ -15,7 +15,7 @@ use buffered_reader::BufferedReaderGeneric; extern crate openpgp; use openpgp::Packet; use openpgp::packet::{BodyLength, Tag}; -use openpgp::parse::PacketParser; +use openpgp::parse::{PacketParserResult, PacketParser}; fn main() { let args: Vec = env::args().collect(); @@ -47,11 +47,11 @@ fn main() { File::open(&args[1]).expect("Failed to open file"), Some(128 * 1024 * 1024) // Use a large buffer. ); - let mut ppo = PacketParser::from_reader(br) + let mut ppr = PacketParser::from_reader(br) .expect("Failed to create reader"); // Iterate over all packets. - while let Some(pp) = ppo { + while let PacketParserResult::Some(pp) = ppr { // While the packet is in the parser, get some data for later. let size = match pp.header.length { BodyLength::Full(n) => Some(n), @@ -61,7 +61,7 @@ fn main() { // Get the packet and advance the parser. let (packet, _, tmp, _) = pp.next() .expect("Failed to get next packet"); - ppo = tmp; + ppr = tmp; packet_count += 1; if let Some(n) = size { -- cgit v1.2.3