diff options
author | Neal H. Walfield <neal@pep.foundation> | 2018-07-02 11:00:00 +0200 |
---|---|---|
committer | Neal H. Walfield <neal@pep.foundation> | 2018-07-02 11:08:39 +0200 |
commit | c9ee0ac8d7689aca241b9b117749a6faf4923676 (patch) | |
tree | de1b416db32a46c1edeae16d59f52596440185e9 /openpgp/examples | |
parent | 36c99d079120607a048284345d4ded09137615de (diff) |
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.
Diffstat (limited to 'openpgp/examples')
-rw-r--r-- | openpgp/examples/statistics.rs | 8 |
1 files changed, 4 insertions, 4 deletions
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<String> = 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 { |