diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2020-05-28 13:38:16 +0200 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2020-05-28 13:38:16 +0200 |
commit | 041661b88c5f1f6cc22fea02761804d5ff42515c (patch) | |
tree | 5a9c5acbddf173a6cb03938533a990a62fbbf745 /openpgp/src/packet_pile.rs | |
parent | 271280e62d1e0ee64a8f4cbb5766b17e3edf947d (diff) |
openpgp: Fix PacketPileParser's API.
- Previously, inspecting the first packet was weird, because only
.next() and .recurse() returned a reference to the underlying
packet parser. Having to call .next() to get the first package
differs from how the packet parser behaves (though I have to admit
that it aligns with Iterator::next()).
- Instead of returning the packet parser result from .next() and
.recurse(), make PacketPileParser deref to it. This allows to
inspect the first packet without weirdly calling .next() first,
and improves code using the PPP in a parsing loop. It also
simplifies the implementation, removing the need for the
`returned_first` hack.
Diffstat (limited to 'openpgp/src/packet_pile.rs')
-rw-r--r-- | openpgp/src/packet_pile.rs | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/openpgp/src/packet_pile.rs b/openpgp/src/packet_pile.rs index e30ab009..af61eb7e 100644 --- a/openpgp/src/packet_pile.rs +++ b/openpgp/src/packet_pile.rs @@ -746,9 +746,8 @@ mod test { .buffer_unread_content() .try_into().unwrap(); - let mut ppr = ppp.recurse().unwrap(); - while ppr.is_some() { - ppr = ppp.recurse().unwrap(); + while ppp.is_some() { + ppp.recurse().unwrap(); } let pile = ppp.finish(); //pile.pretty_print(); @@ -761,10 +760,9 @@ mod test { .buffer_unread_content() .try_into().unwrap(); - let mut ppr = ppp.recurse().unwrap(); - while let Some(pp) = ppr.as_mut() { + while let Some(pp) = ppp.as_ref() { eprintln!("{:?}", pp); - ppr = ppp.recurse().unwrap(); + ppp.recurse().unwrap(); } let pile = ppp.finish(); pile.pretty_print(); |