summaryrefslogtreecommitdiffstats
path: root/openpgp
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2019-05-10 15:09:04 +0200
committerJustus Winter <justus@sequoia-pgp.org>2019-05-10 16:09:19 +0200
commit750e08657b944a8feb404b55a8d55e9621334e09 (patch)
treeb0a003c76bc64fb06cfb49f7300c0af211ae9481 /openpgp
parent6195ae889233ff42136b587ec1ac39bae19c7f85 (diff)
openpgp: Implement {Into,From}Iterator for SubpacketArea.
- This way we can .collect() into a SubpacketArea.
Diffstat (limited to 'openpgp')
-rw-r--r--openpgp/src/packet/signature/subpacket.rs20
1 files changed, 20 insertions, 0 deletions
diff --git a/openpgp/src/packet/signature/subpacket.rs b/openpgp/src/packet/signature/subpacket.rs
index 3406d882..85d17706 100644
--- a/openpgp/src/packet/signature/subpacket.rs
+++ b/openpgp/src/packet/signature/subpacket.rs
@@ -57,6 +57,7 @@
use std::cell::RefCell;
use std::collections::HashMap;
use std::hash::{Hash, Hasher};
+use std::iter::FromIterator;
use std::fmt;
use std::io;
use time;
@@ -435,6 +436,25 @@ impl<'a> Iterator for Iter<'a> {
}
}
+impl<'a> IntoIterator for &'a SubpacketArea {
+ type Item = (usize, usize, Subpacket<'a>);
+ type IntoIter = Iter<'a>;
+
+ fn into_iter(self) -> Self::IntoIter {
+ self.iter()
+ }
+}
+
+impl<'a> FromIterator<(usize, usize, Subpacket<'a>)> for SubpacketArea {
+ fn from_iter<I>(iter: I) -> Self
+ where I: IntoIterator<Item=(usize, usize, Subpacket<'a>)>
+ {
+ use serialize::Serialize;
+ let mut data = Vec::new();
+ iter.into_iter().for_each(|(_, _, s)| s.serialize(&mut data).unwrap());
+ Self::new(data)
+ }
+}
impl SubpacketArea {
/// Returns a new subpacket area based on `data`.