Debian Codegraph @

debian/rust-vendor/zerocopy-derive/tests/enum_known_layout.rs

raw
1 // Copyright 2023 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 // See comment in `include.rs` for why we disable the prelude.
10 #![no_implicit_prelude]
11 #![allow(warnings)]
12
13 include!("include.rs");
14
15 #[derive(imp::KnownLayout)]
16 #[zerocopy(crate = "zerocopy_renamed")]
17 enum Foo {
18 A,
19 }
20
21 util_assert_impl_all!(Foo: imp::KnownLayout);
22
23 #[derive(imp::KnownLayout)]
24 #[zerocopy(crate = "zerocopy_renamed")]
25 enum Bar {
26 A = 0,
27 }
28
29 util_assert_impl_all!(Bar: imp::KnownLayout);
30
31 #[derive(imp::KnownLayout)]
32 #[zerocopy(crate = "zerocopy_renamed")]
33 enum Baz {
34 A = 1,
35 B = 0,
36 }
37
38 util_assert_impl_all!(Baz: imp::KnownLayout);
39
40 // Deriving `KnownLayout` should work if the enum has bounded parameters.
41
42 #[derive(imp::KnownLayout)]
43 #[zerocopy(crate = "zerocopy_renamed")]
44 #[repr(C)]
45 enum WithParams<'a: 'b, 'b: 'a, T: 'a + 'b + imp::KnownLayout, const N: usize>
46 where
47 'a: 'b,
48 'b: 'a,
49 T: 'a + 'b + imp::KnownLayout,
50 {
51 Variant([T; N], imp::PhantomData<&'a &'b ()>),
52 }
53
54 util_assert_impl_all!(WithParams<'static, 'static, u8, 42>: imp::KnownLayout);