protobuf/reflect/enums/
generated.rs

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
//! Generated code support for enum descriptors.

use std::any::TypeId;

use crate::descriptor::FileDescriptorProto;
use crate::EnumFull;
use crate::EnumOrUnknown;

#[doc(hidden)]
pub struct GeneratedEnumDescriptorData {
    pub(crate) name_in_file: &'static str,
    type_id: TypeId,
    enum_or_unknown_type_id: TypeId,
}

impl GeneratedEnumDescriptorData {
    #[doc(hidden)]
    pub fn new<E>(name_in_file: &'static str) -> GeneratedEnumDescriptorData
    where
        E: EnumFull,
    {
        GeneratedEnumDescriptorData {
            name_in_file,
            type_id: TypeId::of::<E>(),
            enum_or_unknown_type_id: TypeId::of::<EnumOrUnknown<E>>(),
        }
    }
}

#[derive(Debug)]
pub(crate) struct GeneratedEnumDescriptor {
    /// Type id of `<E>`
    pub(crate) type_id: TypeId,
    /// Type id of `<ProtobufEnumOrUnknown<E>>`
    pub(crate) _enum_or_unknown_type_id: TypeId,
}

impl GeneratedEnumDescriptor {
    pub(crate) fn new(
        data: GeneratedEnumDescriptorData,
        file_descriptor_proto: &'static FileDescriptorProto,
    ) -> GeneratedEnumDescriptor {
        let GeneratedEnumDescriptorData {
            name_in_file,
            type_id,
            enum_or_unknown_type_id,
        } = data;

        let _ = (name_in_file, file_descriptor_proto);

        GeneratedEnumDescriptor {
            type_id,
            _enum_or_unknown_type_id: enum_or_unknown_type_id,
        }
    }
}