diff --git a/src/ctx.rs b/src/ctx.rs index e24d2dc..6b20dc8 100644 --- a/src/ctx.rs +++ b/src/ctx.rs @@ -830,6 +830,11 @@ impl, const N: usize> TryInt Ok(offset) } } +impl, const N: usize> SizeWith for [T; N] { + fn size_with(ctx: &Ctx) -> usize { + T::size_with(ctx) * N + } +} #[cfg(feature = "std")] impl<'a> TryFromCtx<'a> for &'a CStr { diff --git a/tests/api.rs b/tests/api.rs index b44c726..1e603f1 100644 --- a/tests/api.rs +++ b/tests/api.rs @@ -3,7 +3,7 @@ use std::ops::{Deref, DerefMut}; use scroll::ctx::SizeWith as _; -use scroll::{ctx, Cread, Pread, Result}; +use scroll::{ctx, Cread, Endian, Pread, Result}; #[derive(Default)] pub struct Section<'a> { @@ -376,3 +376,8 @@ fn test_fixed_array_rw() { buf.pwrite([0x1337u16, 0x1337], 0).unwrap(); assert_eq!(buf, bytes); } + +#[test] +fn test_fixed_array_size_with() { + assert_eq!(<[u32; 3]>::size_with(&Endian::Little), 12); +}