1use facet::{Facet, Shape};
2
3pub struct ServiceDescriptor {
8 pub service_name: &'static str,
10
11 pub methods: &'static [&'static MethodDescriptor],
13
14 pub doc: Option<&'static str>,
16}
17
18impl ServiceDescriptor {
19 pub fn by_id(&self, method_id: MethodId) -> Option<&'static MethodDescriptor> {
21 self.methods.iter().find(|m| m.id == method_id).copied()
22 }
23}
24
25pub struct MethodDescriptor {
29 pub id: MethodId,
31
32 pub service_name: &'static str,
34
35 pub method_name: &'static str,
37
38 pub args_shape: &'static Shape,
40
41 pub args: &'static [ArgDescriptor],
43
44 pub return_shape: &'static Shape,
46
47 pub retry: RetryPolicy,
49
50 pub doc: Option<&'static str>,
52}
53
54impl std::fmt::Debug for MethodDescriptor {
55 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
56 f.debug_struct("MethodDescriptor")
57 .field("id", &self.id)
58 .field("service_name", &self.service_name)
59 .field("method_name", &self.method_name)
60 .field("retry", &self.retry)
61 .finish_non_exhaustive()
62 }
63}
64
65#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
67pub struct RetryPolicy {
68 pub persist: bool,
70
71 pub idem: bool,
73}
74
75impl RetryPolicy {
76 pub const VOLATILE: Self = Self {
77 persist: false,
78 idem: false,
79 };
80
81 pub const IDEM: Self = Self {
82 persist: false,
83 idem: true,
84 };
85
86 pub const PERSIST: Self = Self {
87 persist: true,
88 idem: false,
89 };
90
91 pub const PERSIST_IDEM: Self = Self {
92 persist: true,
93 idem: true,
94 };
95}
96
97declare_id!(
98 MethodId, u64
100);
101
102#[derive(Debug)]
107pub struct ArgDescriptor {
108 pub name: &'static str,
110
111 pub shape: &'static Shape,
113}
114
115impl ServiceDescriptor {
116 pub const EMPTY: ServiceDescriptor = ServiceDescriptor {
118 service_name: "<Empty>",
119 methods: &[],
120 doc: None,
121 };
122}