abi_stable/nonexhaustive_enum/
doc_enums.rs

1macro_rules! declare_constructors {
2    ($foo:ident) => {
3        pub fn new_a() -> NonExhaustiveFor<$foo> {
4            // these transmutes are for testing compatibility of enums across versions
5            unsafe { std::mem::transmute(super::example_3::Foo::A.piped(NonExhaustive::new)) }
6        }
7        pub fn new_b(n: i8) -> NonExhaustiveFor<$foo> {
8            unsafe { std::mem::transmute(super::example_3::Foo::B(n).piped(NonExhaustive::new)) }
9        }
10
11        pub fn new_c() -> NonExhaustiveFor<$foo> {
12            unsafe { std::mem::transmute(super::example_3::Foo::C.piped(NonExhaustive::new)) }
13        }
14    };
15}
16
17pub mod example_1 {
18    use crate::nonexhaustive_enum::{NonExhaustive, NonExhaustiveFor};
19    use core_extensions::SelfOps;
20
21    #[repr(u8)]
22    #[derive(StableAbi, Debug, Clone, PartialEq, Eq)]
23    #[sabi(kind(WithNonExhaustive(size = [usize;4], traits(Debug, Clone, PartialEq))))]
24    pub enum Foo {
25        A,
26    }
27
28    declare_constructors! {Foo}
29}
30
31pub mod example_2 {
32    use crate::nonexhaustive_enum::{NonExhaustive, NonExhaustiveFor};
33    use core_extensions::SelfOps;
34
35    #[repr(u8)]
36    #[derive(StableAbi, Debug, Clone, PartialEq, Eq)]
37    #[sabi(kind(WithNonExhaustive(size = [usize;4], traits(Debug, Clone, PartialEq))))]
38    pub enum Foo {
39        A,
40        B(i8),
41    }
42
43    declare_constructors! {Foo}
44}
45
46pub mod example_3 {
47    use crate::nonexhaustive_enum::{NonExhaustive, NonExhaustiveFor};
48    use core_extensions::SelfOps;
49
50    #[repr(u8)]
51    #[derive(StableAbi, Debug, Clone, PartialEq, Eq)]
52    #[sabi(kind(WithNonExhaustive(size = [usize;4], traits(Debug, Clone, PartialEq))))]
53    pub enum Foo {
54        A,
55        B(i8),
56        C,
57    }
58
59    declare_constructors! {Foo}
60}