type_reflect_core/
type_description.rs

1use crate::{Inflectable, Inflection};
2
3#[derive(Clone, Debug)]
4pub struct NamedType {
5    pub name: String,
6    pub generic_args: Vec<Box<Type>>,
7}
8
9#[derive(Clone, Debug)]
10pub enum TransparentTypeCase {
11    Box,
12    Rc,
13    Arc,
14}
15
16#[derive(Clone, Debug)]
17pub struct TransparentType {
18    pub case: TransparentTypeCase,
19    pub type_: Box<Type>,
20}
21
22#[derive(Clone, Debug)]
23pub enum Type {
24    Named(NamedType),
25    String,
26    Int,
27    UnsignedInt,
28    Float,
29    Boolean,
30    Transparent(TransparentType),
31    Option(Box<Type>),
32    Array(Box<Type>),
33    Map { key: Box<Type>, value: Box<Type> },
34}
35
36#[derive(Clone, Debug)]
37pub struct NamedField {
38    pub name: String,
39    pub type_: Type,
40}
41
42#[derive(Clone, Debug)]
43pub struct EnumCase {
44    pub name: String,
45    pub type_: TypeFieldsDefinition,
46    pub inflection: Inflection,
47}
48
49impl EnumCase {
50    pub fn name_with_inflection(&self) -> String {
51        self.name.inflect(self.inflection)
52    }
53}
54
55/**
56The TypeFieldDefinition represents the set of fields for a type
57
58This is used both in the context of a struct definition, and for enum variants
59*/
60#[derive(Clone, Debug)]
61pub enum TypeFieldsDefinition {
62    /**
63    The Unit field definition describes a type which does not contain data
64    */
65    Unit,
66    /**
67    The Tuple field definition describes a type which contains anonymous fields, identified by index
68    */
69    Tuple(Vec<Type>),
70    /**
71    The Named field definition describes a type which contains named fields, identified by name
72    */
73    Named(Vec<NamedField>),
74}
75
76#[derive(Clone, Debug)]
77pub enum EnumType {
78    Simple,
79    Complex {
80        case_key: String,
81        content_key: Option<String>,
82    },
83    Untagged,
84}
85
86// #[derive(Clone, Debug)]
87// pub struct TypeSlot {
88//     pub optional: bool,
89//     pub type_: Type,
90// }