1 // Copyright 2019 The Fuchsia Authors
2 //
3 // Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
4 // <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
5 // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
6 // This file may not be copied, modified, or distributed except according to
7 // those terms.
8
9 extern crate zerocopy;
10
11 #[path = "../util.rs"]
12 mod util;
13
14 use core::marker::PhantomData;
15
16 use {
17 static_assertions::assert_impl_all,
18 zerocopy::{AsBytes, FromBytes, FromZeroes, Unaligned},
19 };
20
21 use self::util::NotZerocopy;
22
main()23 fn main() {}
24
25 // Test generic transparent structs
26
27 #[derive(AsBytes, FromZeroes, FromBytes, Unaligned)]
28 #[repr(transparent)]
29 struct TransparentStruct<T> {
30 inner: T,
31 _phantom: PhantomData<()>,
32 }
33
34 // It should be legal to derive these traits on a transparent struct, but it
35 // must also ensure the traits are only implemented when the inner type
36 // implements them.
37 assert_impl_all!(TransparentStruct<NotZerocopy>: FromZeroes);
38 assert_impl_all!(TransparentStruct<NotZerocopy>: FromBytes);
39 assert_impl_all!(TransparentStruct<NotZerocopy>: AsBytes);
40 assert_impl_all!(TransparentStruct<NotZerocopy>: Unaligned);
41