1use std::num::NonZero;
2
3use object_rainbow::{
4 numeric::{Be, Le},
5 *,
6};
7
8#[derive(
9 ToOutput, InlineOutput, ListHashes, Topological, Tagged, Size, Parse, ParseInline, MaybeHasNiche,
10)]
11#[tags("example")]
12pub struct DeriveExample<A, B> {
13 a: A,
14 #[tags(skip)]
15 b: B,
16}
17
18#[derive(
19 Enum,
20 ToOutput,
21 InlineOutput,
22 ListHashes,
23 Topological,
24 Tagged,
25 Size,
26 Parse,
27 ParseInline,
28 MaybeHasNiche,
29)]
30#[enumtag("Le<u16>")]
31enum Test<U, V, Y> {
32 A,
33 B(U),
34 C { y: Y, x: V },
35}
36
37#[derive(
38 Enum,
39 ToOutput,
40 InlineOutput,
41 ListHashes,
42 Topological,
43 Tagged,
44 Size,
45 Parse,
46 ParseInline,
47 MaybeHasNiche,
48)]
49#[enumtag("Le<NonZero<u16>>")]
50enum Stuff<T> {
51 A(T),
52 B(T),
53 C(T),
54 D(T),
55 E(T),
56}
57
58#[derive(
59 Enum,
60 ToOutput,
61 InlineOutput,
62 ListHashes,
63 Topological,
64 Tagged,
65 Size,
66 Parse,
67 ParseInline,
68 MaybeHasNiche,
69)]
70#[enumtag("bool")]
71enum Either<L, R> {
72 Left(L),
73 Right(R),
74}
75
76#[derive(
77 Enum,
78 ToOutput,
79 InlineOutput,
80 ListHashes,
81 Topological,
82 Tagged,
83 Size,
84 Parse,
85 ParseInline,
86 MaybeHasNiche,
87)]
88#[enumtag("Le<u8>")]
89enum Abc {
90 NoNiche(Le<u8>),
91 Niche(bool),
92}
93
94fn main() {
95 println!("{}", hex::encode(DeriveExample::<(), ()>::HASH));
96 println!("{}", DeriveExample::<Be<u8>, Le<u8>>::SIZE);
97 println!("{}", Test::<(), (), ()>::SIZE);
98 println!("{}", Option::<Test<(), (), ()>>::SIZE);
99 println!("{}", Option::<Stuff<()>>::SIZE);
100 println!("{}", Option::<Stuff<bool>>::SIZE);
101 println!("{:?}", None::<Stuff<(bool, ())>>.vec());
102 println!("{}", Option::<Either<bool, Option<Option<()>>>>::SIZE);
103 println!("{:?}", None::<Abc>.vec());
104 println!("{:?}", None::<(bool, bool)>.vec());
105 Option::<Abc>::parse_slice_refless(&[1, 2]).unwrap();
106}