1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
//! Parsed enumeration declarations before semantic validation.
use alloc::vec::Vec;
use syn::{Generics, Ident};
use crate::{
field::Fields,
syntax::{Config, Declaration},
};
/// A parsed enumeration error declaration.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct Enumeration {
/// Parsed container-wide generation options.
config: Config,
/// Source enumeration identifier.
name: Ident,
/// Source generic parameters.
generics: Generics,
/// Parsed error variants.
variants: Vec<Variant>,
}
impl Enumeration {
/// Construct a parsed enumeration declaration.
#[inline]
#[must_use]
pub const fn new(config: Config, name: Ident, generics: Generics, variants: Vec<Variant>) -> Self {
Self {
config,
name,
generics,
variants,
}
}
/// Consume the enumeration into its parsed components.
#[inline]
#[must_use]
pub fn parts(self) -> (Config, Ident, Generics, Vec<Variant>) {
let Self {
config,
name,
generics,
variants,
} = self;
(config, name, generics, variants)
}
}
/// A parsed error enum variant declaration.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct Variant {
/// Source variant identifier.
name: Ident,
/// Parsed variant fields.
fields: Fields,
/// Parsed error behavior declarations.
declaration: Declaration,
}
impl Variant {
/// Construct a parsed enum variant declaration.
#[inline]
#[must_use]
pub const fn new(name: Ident, fields: Fields, declaration: Declaration) -> Self {
Self { name, fields, declaration }
}
/// Consume the variant into its parsed components.
#[inline]
#[must_use]
pub fn parts(self) -> (Ident, Fields, Declaration) {
let Self { name, fields, declaration } = self;
(name, fields, declaration)
}
}