diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2020-04-09 16:42:59 +0200 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2020-04-09 18:18:30 +0200 |
commit | 2e1eec5fe4157a391a13554ff7df3075cfe043cc (patch) | |
tree | 03ac579ba58d27c08a7ac16ca16f687d1a9456ed /openpgp/src/packet_pile.rs | |
parent | c1516c59709fa47d13100daddb57657008a793c3 (diff) |
openpgp: Make PacketParserResult a std::result::Result.
- This avoids the partial implementation imitating
std::option::Option, replacing it with std::result::Result.
- As a benefit, std::result::Result is in the prelude, simplifying a
lot of parsing loops.
Diffstat (limited to 'openpgp/src/packet_pile.rs')
-rw-r--r-- | openpgp/src/packet_pile.rs | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/openpgp/src/packet_pile.rs b/openpgp/src/packet_pile.rs index 250d9f14..d3ced30f 100644 --- a/openpgp/src/packet_pile.rs +++ b/openpgp/src/packet_pile.rs @@ -349,7 +349,7 @@ impl<'a> TryFrom<PacketParserResult<'a>> for PacketPile { // ppo.recursion_depth and leave the rest of the message, but // it is hard to imagine that that is what the caller wants. // Instead of hiding that error, fail fast. - if let PacketParserResult::Some(ref pp) = ppr { + if let Ok(ref pp) = ppr { if pp.recursion_depth() != 0 { return Err(Error::InvalidOperation( format!("Expected top-level packet, \ @@ -363,7 +363,7 @@ impl<'a> TryFrom<PacketParserResult<'a>> for PacketPile { let mut last_position = 0; - if ppr.is_none() { + if ppr.is_err() { // Empty message. return Ok(PacketPile::from(Vec::new())); } @@ -414,7 +414,7 @@ impl<'a> TryFrom<PacketParserResult<'a>> for PacketPile { container.children_mut().unwrap().push(packet); - if ppr.is_none() { + if ppr.is_err() { break 'outer; } @@ -561,7 +561,7 @@ mod test { .try_into().unwrap(); let mut ppr = ppp.recurse().unwrap(); - while ppr.is_some() { + while ppr.is_ok() { ppr = ppp.recurse().unwrap(); } let pile = ppp.finish(); @@ -576,7 +576,7 @@ mod test { .try_into().unwrap(); let mut ppr = ppp.recurse().unwrap(); - while let Some(pp) = ppr.as_mut() { + while let Ok(pp) = ppr.as_mut() { eprintln!("{:?}", pp); ppr = ppp.recurse().unwrap(); } @@ -620,13 +620,13 @@ mod test { let mut count = 0; loop { - if let PacketParserResult::Some(pp2) = ppr { + if let Ok(pp2) = ppr { count += 1; let packet_depth = pp2.recursion_depth(); let pp2 = pp2.recurse().unwrap().1; assert_eq!(packet_depth, count - 1); - if pp2.is_some() { + if pp2.is_ok() { assert_eq!(pp2.as_ref().unwrap().recursion_depth(), count); } ppr = pp2; @@ -664,7 +664,7 @@ mod test { // recurse should now not recurse. Since there is nothing // following the compressed packet, ppr should be EOF. let (packet, ppr) = pp.next().unwrap(); - assert!(ppr.is_none()); + assert!(ppr.is_err()); // Get the rest of the content and put the initial byte that // we stole back. @@ -680,7 +680,7 @@ mod test { // And we're done... let ppr = pp.next().unwrap().1; - assert!(ppr.is_none()); + assert!(ppr.is_err()); } #[test] |