From: Matt Corallo Date: Fri, 23 Jul 2021 18:11:45 +0000 (+0000) Subject: Swap VecWriteWrapper's inner for an iterator to make it more generic X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=1a7dbe8cde534a5585451db5f6f33b5caa0f6abf;p=rust-lightning Swap VecWriteWrapper's inner for an iterator to make it more generic --- diff --git a/lightning/src/util/events.rs b/lightning/src/util/events.rs index e90f443b0..f26b70589 100644 --- a/lightning/src/util/events.rs +++ b/lightning/src/util/events.rs @@ -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 } => { diff --git a/lightning/src/util/ser.rs b/lightning/src/util/ser.rs index 8fb72a8f9..cb883d8b2 100644 --- a/lightning/src/util/ser.rs +++ b/lightning/src/util/ser.rs @@ -244,12 +244,12 @@ impl Readable for OptionDeserWrapper { } } -/// Wrapper to write each element of a Vec with no length prefix -pub(crate) struct VecWriteWrapper<'a, T: Writeable>(pub &'a Vec); -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(pub I) where I::Item: Writeable; +impl Writeable for IterWriteWrapper where I::Item: Writeable { #[inline] fn write(&self, writer: &mut W) -> Result<(), io::Error> { - for ref v in self.0.iter() { + for v in self.0.clone() { v.write(writer)?; } Ok(()) diff --git a/lightning/src/util/ser_macros.rs b/lightning/src/util/ser_macros.rs index 165d1f1ed..43bbe3d68 100644 --- a/lightning/src/util/ser_macros.rs +++ b/lightning/src/util/ser_macros.rs @@ -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 {