fack_codegen/enumerate.rs
1//! The enumeration error type.
2
3use alloc::vec::Vec;
4
5use syn::{Generics, Ident, Type};
6
7use super::{
8 common::{FieldRef, Format, ImportRoot, InlineOptions, Transparent},
9 structure::FieldList,
10};
11
12/// An enumeration that corresponds to an **error** type.
13#[derive(Clone, Debug, PartialEq, Eq, Hash)]
14pub struct Enumeration {
15 /// The inline behavior for this enumeration.
16 pub inline_opts: Option<InlineOptions>,
17
18 /// The import root for this enumeration.
19 pub root_import: Option<ImportRoot>,
20
21 /// The identifier of this enumeration.
22 pub name_ident: Ident,
23
24 /// The generic parameters of this enumeration.
25 pub generics: Generics,
26
27 /// The variant list of this enumeration.
28 pub variant_list: Vec<Variant>,
29}
30
31/// A single variant of an enumeration.
32#[derive(Clone, Debug, PartialEq, Eq, Hash)]
33pub enum Variant {
34 /// A struct-like variant that is composed of a list of fields.
35 Struct {
36 /// The formatter setting for this variant.
37 format: Format,
38
39 /// The field to be used as the source of the error.
40 source_field: Option<FieldRef>,
41
42 /// The name of the current variant.
43 variant_name: Ident,
44
45 /// The field list of this struct-like variant.
46 field_list: FieldList,
47 },
48
49 /// An unit variant that has no fields.
50 Unit {
51 /// The formatter setting for this variant.
52 format: Format,
53
54 /// The name of the current variant.
55 variant_name: Ident,
56 },
57
58 /// A transparent variant that is transparent over some downstream type.s
59 Transparent {
60 /// The transparence setting for this variant.
61 transparent: Transparent,
62
63 /// The name of the current variant.
64 variant_name: Ident,
65
66 /// The field list of this struct-like variant.
67 field_list: FieldList,
68 },
69
70 /// A forward variant that forwards to one of its fields.
71 Forward {
72 /// The formatter setting for this variant.
73 format: Format,
74
75 /// The name of the current variant.
76 variant_name: Ident,
77
78 /// The forwarded field.
79 field_ref: FieldRef,
80
81 /// The type of the forwarded field.
82 field_type: Type,
83 },
84}