pilota_thrift_parser/descriptor/
mod.rs1mod annotation;
2mod constant;
3mod enum_;
4mod field;
5mod function;
6mod identifier;
7mod include;
8mod literal;
9mod namespace;
10mod service;
11mod struct_;
12mod ty;
13mod typedef;
14
15use std::{hash::Hash, path::PathBuf, sync::Arc};
16
17pub use annotation::{Annotation, Annotations};
18use bytes::Bytes;
19pub use constant::{ConstValue, Constant, DoubleConstant, IntConstant};
20pub use enum_::{Enum, EnumValue};
21use faststr::FastStr;
22pub use field::{Attribute, Field};
23pub use function::Function;
24pub use identifier::Ident;
25pub use include::{CppInclude, Include};
26pub use literal::Literal;
27pub use namespace::{Namespace, Scope};
28pub use service::Service;
29pub use struct_::{Exception, Struct, StructLike, Union};
30pub use ty::{CppType, Ty, Type};
31pub use typedef::Typedef;
32
33pub struct Components {}
34
35#[derive(Debug, Clone)]
36pub struct Path {
37 pub segments: Arc<[Ident]>,
38}
39
40impl<Item> FromIterator<Item> for Path
41where
42 Item: Into<Ident>,
43{
44 fn from_iter<T: IntoIterator<Item = Item>>(iter: T) -> Self {
45 Path {
46 segments: iter.into_iter().map(Into::into).collect(),
47 }
48 }
49}
50
51#[derive(Debug)]
52pub enum Item {
53 Include(Include),
54 CppInclude(CppInclude),
55 Namespace(Namespace),
56 Typedef(Typedef),
57 Constant(Constant),
58 Enum(Enum),
59 Struct(Struct),
60 Union(Union),
61 Exception(Exception),
62 Service(Service),
63}
64
65macro_rules! item_from {
66 ($t: tt) => {
67 impl From<$t> for Item {
68 fn from(i: $t) -> Self {
69 Item::$t(i)
70 }
71 }
72 };
73}
74
75item_from!(Typedef);
76item_from!(Constant);
77item_from!(Enum);
78item_from!(Struct);
79item_from!(Union);
80item_from!(Exception);
81item_from!(Service);
82
83#[derive(Default, Debug)]
84pub struct File {
85 pub path: Arc<PathBuf>,
86 pub uuid: FastStr,
87 pub package: Option<Path>,
88 pub items: Vec<Item>,
89 pub descriptor: Bytes,
90 pub comments: FastStr,
91}
92
93impl PartialEq for File {
94 fn eq(&self, other: &Self) -> bool {
95 self.path == other.path
96 }
97}
98
99impl Eq for File {}
100
101impl PartialOrd for File {
102 fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
103 Some(self.cmp(other))
104 }
105}
106
107impl Ord for File {
108 fn cmp(&self, other: &Self) -> std::cmp::Ordering {
109 self.path.cmp(&other.path)
110 }
111}
112
113impl Hash for File {
114 fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
115 self.path.hash(state);
116 }
117}