Skip to content
This repository has been archived by the owner on Jul 29, 2024. It is now read-only.

Commit

Permalink
fix error implement for reading [T;N].
Browse files Browse the repository at this point in the history
fix #130

Signed-off-by: Yang, Longlong <[email protected]>
  • Loading branch information
longlongyang authored and jyao1 committed Oct 31, 2023
1 parent 5a9397a commit 490b73c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion codec/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "codec"
version = "0.2.0"
version = "0.2.1"
authors = [
"Xiaoyu Lu <[email protected]>",
"Jiewen Yao <[email protected]>",
Expand Down
11 changes: 8 additions & 3 deletions codec/src/codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,17 +318,22 @@ impl Codec for u128 {
}
}

impl<T: Codec + Copy, const N: usize> Codec for [T; N] {
impl<T: Codec + Copy + Default, const N: usize> Codec for [T; N] {
fn encode(&self, bytes: &mut Writer) -> Result<usize, EncodeErr> {
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<Self> {
Some([T::read(reader)?; N])
let mut target = [T::default(); N];
for t in target.iter_mut() {
*t = T::read(reader)?;
}

Some(target)
}
}

Expand Down

0 comments on commit 490b73c

Please sign in to comment.