]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Swap VecWriteWrapper's inner for an iterator to make it more generic
authorMatt Corallo <git@bluematt.me>
Fri, 23 Jul 2021 18:11:45 +0000 (18:11 +0000)
committerMatt Corallo <git@bluematt.me>
Tue, 30 Nov 2021 21:43:50 +0000 (21:43 +0000)
lightning/src/util/events.rs
lightning/src/util/ser.rs
lightning/src/util/ser_macros.rs

index e90f443b0c2c42c1126bf4eb9805def24d4cf5bb..f26b70589745a713d919e6e6d09b5c272fd6e37b 100644 (file)
@@ -21,7 +21,7 @@ use ln::msgs;
 use ln::msgs::DecodeError;
 use ln::{PaymentPreimage, PaymentHash, PaymentSecret};
 use routing::network_graph::NetworkUpdate;
-use util::ser::{BigSize, FixedLengthReader, Writeable, Writer, MaybeReadable, Readable, VecReadWrapper, VecWriteWrapper};
+use util::ser::{BigSize, FixedLengthReader, Writeable, Writer, MaybeReadable, Readable, VecReadWrapper, IterWriteWrapper};
 use routing::router::{RouteHop, RouteParameters};
 
 use bitcoin::Transaction;
@@ -424,7 +424,7 @@ impl Writeable for Event {
                        &Event::SpendableOutputs { ref outputs } => {
                                5u8.write(writer)?;
                                write_tlv_fields!(writer, {
-                                       (0, VecWriteWrapper(outputs), required),
+                                       (0, IterWriteWrapper(outputs.iter()), required),
                                });
                        },
                        &Event::PaymentForwarded { fee_earned_msat, claim_from_onchain_tx } => {
index 8fb72a8f9fe643f56cfc259e5b7214b56a4fb761..cb883d8b2e85ac014037dc0dfeb43a26ea2e86e7 100644 (file)
@@ -244,12 +244,12 @@ impl<T: Readable> Readable for OptionDeserWrapper<T> {
        }
 }
 
-/// Wrapper to write each element of a Vec with no length prefix
-pub(crate) struct VecWriteWrapper<'a, T: Writeable>(pub &'a Vec<T>);
-impl<'a, T: Writeable> Writeable for VecWriteWrapper<'a, T> {
+/// Wrapper to write each element of an iterator with no length prefix
+pub(crate) struct IterWriteWrapper<I: Iterator + Clone>(pub I) where I::Item: Writeable;
+impl<I: Iterator + Clone> Writeable for IterWriteWrapper<I> where I::Item: Writeable {
        #[inline]
        fn write<W: Writer>(&self, writer: &mut W) -> Result<(), io::Error> {
-               for ref v in self.0.iter() {
+               for v in self.0.clone() {
                        v.write(writer)?;
                }
                Ok(())
index 165d1f1edbacea61438ef3426828a1195336a39e..43bbe3d68c43c2961335009fa849f106bec69fac 100644 (file)
@@ -17,7 +17,7 @@ macro_rules! encode_tlv {
                $field.write($stream)?;
        };
        ($stream: expr, $type: expr, $field: expr, vec_type) => {
-               encode_tlv!($stream, $type, ::util::ser::VecWriteWrapper(&$field), required);
+               encode_tlv!($stream, $type, ::util::ser::IterWriteWrapper($field.iter()), required);
        };
        ($stream: expr, $optional_type: expr, $optional_field: expr, option) => {
                if let Some(ref field) = $optional_field {
@@ -66,7 +66,7 @@ macro_rules! get_varint_length_prefixed_tlv_length {
                $len.0 += field_len;
        };
        ($len: expr, $type: expr, $field: expr, vec_type) => {
-               get_varint_length_prefixed_tlv_length!($len, $type, ::util::ser::VecWriteWrapper(&$field), required);
+               get_varint_length_prefixed_tlv_length!($len, $type, ::util::ser::IterWriteWrapper($field.iter()), required);
        };
        ($len: expr, $optional_type: expr, $optional_field: expr, option) => {
                if let Some(ref field) = $optional_field {