diff options
Diffstat (limited to 'tests/struct_from_bytes.rs')
-rw-r--r-- | tests/struct_from_bytes.rs | 57 |
1 files changed, 31 insertions, 26 deletions
diff --git a/tests/struct_from_bytes.rs b/tests/struct_from_bytes.rs index 7ebc300..5dc68d2 100644 --- a/tests/struct_from_bytes.rs +++ b/tests/struct_from_bytes.rs @@ -4,52 +4,57 @@ #![allow(warnings)] -use std::{marker::PhantomData, option::IntoIter}; +mod util; -use zerocopy::FromBytes; +use std::{marker::PhantomData, option::IntoIter}; -struct IsFromBytes<T: FromBytes>(T); +use { + static_assertions::assert_impl_all, + zerocopy::{FromBytes, FromZeroes}, +}; -// Fail compilation if `$ty: !FromBytes`. -macro_rules! is_from_bytes { - ($ty:ty) => { - const _: () = { - let _: IsFromBytes<$ty>; - }; - }; -} +use crate::util::AU16; // A struct is `FromBytes` if: // - all fields are `FromBytes` -#[derive(FromBytes)] +#[derive(FromZeroes, FromBytes)] struct Zst; -is_from_bytes!(Zst); +assert_impl_all!(Zst: FromBytes); -#[derive(FromBytes)] +#[derive(FromZeroes, FromBytes)] struct One { a: u8, } -is_from_bytes!(One); +assert_impl_all!(One: FromBytes); -#[derive(FromBytes)] +#[derive(FromZeroes, FromBytes)] struct Two { a: u8, b: Zst, } -is_from_bytes!(Two); +assert_impl_all!(Two: FromBytes); + +#[derive(FromZeroes, FromBytes)] +struct Unsized { + a: [u8], +} + +assert_impl_all!(Unsized: FromBytes); -#[derive(FromBytes)] -struct TypeParams<'a, T, I: Iterator> { - a: T, - c: I::Item, - d: u8, - e: PhantomData<&'a [u8]>, - f: PhantomData<&'static str>, - g: PhantomData<String>, +#[derive(FromZeroes, FromBytes)] +struct TypeParams<'a, T: ?Sized, I: Iterator> { + a: I::Item, + b: u8, + c: PhantomData<&'a [u8]>, + d: PhantomData<&'static str>, + e: PhantomData<String>, + f: T, } -is_from_bytes!(TypeParams<'static, (), IntoIter<()>>); +assert_impl_all!(TypeParams<'static, (), IntoIter<()>>: FromBytes); +assert_impl_all!(TypeParams<'static, AU16, IntoIter<()>>: FromBytes); +assert_impl_all!(TypeParams<'static, [AU16], IntoIter<()>>: FromBytes); |