]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Don't initialise Vecs being read with VecReadWrapper explicitly
authorMatt Corallo <git@bluematt.me>
Sun, 1 Aug 2021 02:34:08 +0000 (02:34 +0000)
committerMatt Corallo <git@bluematt.me>
Tue, 24 Aug 2021 17:08:41 +0000 (17:08 +0000)
This simplifies the tlv serialization read macro somewhat by
allowing callsites to simply read into an `Option<Vec>` instead of
needing to read into an `Option<VecReadWrapper>` when using
`vec_type`.

lightning/src/util/ser_macros.rs

index 5178732c7457e93745d39319fa2f2ecee99a80dd..e8bd3326babfa3dc74f457e90ac84441c7c73aba 100644 (file)
@@ -154,7 +154,8 @@ macro_rules! decode_tlv {
                $field = ser::Readable::read(&mut $reader)?;
        }};
        ($reader: expr, $field: ident, vec_type) => {{
-               $field = Some(ser::Readable::read(&mut $reader)?);
+               let f: ::util::ser::VecReadWrapper<_> = ser::Readable::read(&mut $reader)?;
+               $field = Some(f.0);
        }};
        ($reader: expr, $field: ident, option) => {{
                $field = Some(ser::Readable::read(&mut $reader)?);
@@ -399,7 +400,7 @@ macro_rules! init_tlv_based_struct_field {
                $field.0.unwrap()
        };
        ($field: ident, vec_type) => {
-               $field.unwrap().0
+               $field.unwrap()
        };
 }
 
@@ -411,7 +412,7 @@ macro_rules! init_tlv_field_var {
                let mut $field = ::util::ser::OptionDeserWrapper(None);
        };
        ($field: ident, vec_type) => {
-               let mut $field = Some(::util::ser::VecReadWrapper(Vec::new()));
+               let mut $field = Some(Vec::new());
        };
        ($field: ident, option) => {
                let mut $field = None;