diff options
Diffstat (limited to 'openpgp/src')
-rw-r--r-- | openpgp/src/packet_pile.rs | 2 | ||||
-rw-r--r-- | openpgp/src/parse.rs | 27 | ||||
-rw-r--r-- | openpgp/src/parse/packet_pile_parser.rs | 10 |
3 files changed, 20 insertions, 19 deletions
diff --git a/openpgp/src/packet_pile.rs b/openpgp/src/packet_pile.rs index bb505a96..07ca3561 100644 --- a/openpgp/src/packet_pile.rs +++ b/openpgp/src/packet_pile.rs @@ -760,7 +760,7 @@ mod test { .buffer_unread_content() .try_into().unwrap(); - while let Some(pp) = ppp.as_ref() { + while let Ok(pp) = ppp.as_ref() { eprintln!("{:?}", pp); ppp.recurse().unwrap(); } diff --git a/openpgp/src/parse.rs b/openpgp/src/parse.rs index 16c7ec6e..f36f634c 100644 --- a/openpgp/src/parse.rs +++ b/openpgp/src/parse.rs @@ -175,6 +175,7 @@ use std::str; use std::mem; use std::fmt; use std::path::Path; +use std::result::Result as StdResult; use ::buffered_reader::*; @@ -3315,20 +3316,20 @@ impl<'a> PacketParserResult<'a> { } /// Like `Option::as_ref`(). - pub fn as_ref(&self) -> Option<&PacketParser<'a>> { - if let PacketParserResult::Some(ref pp) = self { - Some(pp) - } else { - None + pub fn as_ref(&self) + -> StdResult<&PacketParser<'a>, &PacketParserEOF> { + match self { + PacketParserResult::Some(pp) => Ok(pp), + PacketParserResult::EOF(eof) => Err(eof), } } /// Like `Option::as_mut`(). - pub fn as_mut(&mut self) -> Option<&mut PacketParser<'a>> { - if let PacketParserResult::Some(ref mut pp) = self { - Some(pp) - } else { - None + pub fn as_mut(&mut self) + -> StdResult<&mut PacketParser<'a>, &mut PacketParserEOF> { + match self { + PacketParserResult::Some(pp) => Ok(pp), + PacketParserResult::EOF(eof) => Err(eof), } } @@ -3345,12 +3346,12 @@ impl<'a> PacketParserResult<'a> { } /// Like `Option::map`(). - pub fn map<U, F>(self, f: F) -> Option<U> + pub fn map<U, F>(self, f: F) -> StdResult<U, PacketParserEOF> where F: FnOnce(PacketParser<'a>) -> U { match self { - PacketParserResult::Some(x) => Some(f(x)), - PacketParserResult::EOF(_) => None, + PacketParserResult::Some(x) => Ok(f(x)), + PacketParserResult::EOF(e) => Err(e), } } } diff --git a/openpgp/src/parse/packet_pile_parser.rs b/openpgp/src/parse/packet_pile_parser.rs index 2540026a..78483b82 100644 --- a/openpgp/src/parse/packet_pile_parser.rs +++ b/openpgp/src/parse/packet_pile_parser.rs @@ -54,7 +54,7 @@ use buffered_reader::BufferedReader; /// # include_bytes!("../../tests/data/keys/public-key.gpg"); /// # let mut n = 0; /// let mut ppp = PacketPileParser::from_bytes(message_data)?; -/// while let Some(pp) = ppp.as_ref() { +/// while let Ok(pp) = ppp.as_ref() { /// eprintln!("{:?}", pp); /// ppp.recurse()?; /// # n += 1; @@ -198,7 +198,7 @@ impl<'a> PacketPileParser<'a> { /// let message_data: &[u8] = // ... /// # include_bytes!("../../tests/data/messages/compressed-data-algo-0.pgp"); /// let mut ppp = PacketPileParser::from_bytes(message_data)?; - /// while let Some(pp) = ppp.as_ref() { + /// while let Ok(pp) = ppp.as_ref() { /// // Do something interesting with `pp` here. /// /// // Start parsing the next packet, recursing. @@ -251,7 +251,7 @@ impl<'a> PacketPileParser<'a> { /// let message_data: &[u8] = // ... /// # include_bytes!("../../tests/data/messages/compressed-data-algo-0.pgp"); /// let mut ppp = PacketPileParser::from_bytes(message_data)?; - /// while let Some(pp) = ppp.as_ref() { + /// while let Ok(pp) = ppp.as_ref() { /// // Do something interesting with `pp` here. /// /// // Start parsing the next packet. @@ -296,7 +296,7 @@ impl<'a> PacketPileParser<'a> { /// let message_data: &[u8] = // ... /// # include_bytes!("../../tests/data/messages/compressed-data-algo-0.pgp"); /// let mut ppp = PacketPileParser::from_bytes(message_data)?; - /// while let Some(pp) = ppp.as_ref() { + /// while let Ok(pp) = ppp.as_ref() { /// match pp.packet { /// Packet::CompressedData(_) => /// assert_eq!(ppp.recursion_depth(), Some(0)), @@ -424,7 +424,7 @@ fn message_parser_reader_interface() { let mut ppp = PacketPileParser::from_bytes( crate::tests::message("compressed-data-algo-1.gpg")).unwrap(); let mut count = 0; - while let Some(pp) = ppp.as_mut() { + while let Ok(pp) = ppp.as_mut() { if let Packet::Literal(_) = pp.packet { assert_eq!(count, 1); // The *second* packet. |