diff --git a/Cargo.lock b/Cargo.lock index c0d9c202..240db571 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -404,7 +404,7 @@ dependencies = [ [[package]] name = "codec" -version = "0.2.0" +version = "0.2.1" [[package]] name = "colorchoice" diff --git a/codec/Cargo.toml b/codec/Cargo.toml index d154f086..551a83c9 100644 --- a/codec/Cargo.toml +++ b/codec/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "codec" -version = "0.2.0" +version = "0.2.1" authors = [ "Xiaoyu Lu ", "Jiewen Yao ", diff --git a/codec/src/codec.rs b/codec/src/codec.rs index 1db3fa40..49fb0486 100644 --- a/codec/src/codec.rs +++ b/codec/src/codec.rs @@ -318,17 +318,22 @@ impl Codec for u128 { } } -impl Codec for [T; N] { +impl Codec for [T; N] { fn encode(&self, bytes: &mut Writer) -> Result { let used = bytes.used(); - for d in self.as_ref() { + for d in self.iter() { let _ = d.encode(bytes)?; } Ok(bytes.used() - used) } fn read(reader: &mut Reader) -> Option { - Some([T::read(reader)?; N]) + let mut target = [T::default(); N]; + for t in target.iter_mut() { + *t = T::read(reader)?; + } + + Some(target) } }