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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
use std::fmt;
mod error;
pub use self::error::*;
mod options;
pub use self::options::*;
mod roles;
pub use self::roles::*;
mod value;
pub use self::value::*;
#[allow(clippy::trivially_copy_pass_by_ref)]
fn is_not(b: &bool) -> bool {
!*b
}
#[derive(PartialEq, Debug, Clone, Copy)]
pub enum MatchingPolicy {
Prefix,
Wildcard,
Strict,
}
#[derive(PartialEq, Debug, Clone, Copy)]
pub enum InvocationPolicy {
Single,
RoundRobin,
Random,
First,
Last,
}
struct MatchingPolicyVisitor;
struct InvocationPolicyVisitor;
impl MatchingPolicy {
#[allow(clippy::trivially_copy_pass_by_ref)]
#[inline]
fn is_strict(&self) -> bool {
*self == MatchingPolicy::Strict
}
}
impl InvocationPolicy {
#[allow(clippy::trivially_copy_pass_by_ref)]
#[inline]
fn is_single(&self) -> bool {
*self == InvocationPolicy::Single
}
}
impl Default for MatchingPolicy {
#[inline]
fn default() -> MatchingPolicy {
MatchingPolicy::Strict
}
}
impl Default for InvocationPolicy {
#[inline]
fn default() -> InvocationPolicy {
InvocationPolicy::Single
}
}
impl serde::Serialize for MatchingPolicy {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
let ser_str = match *self {
MatchingPolicy::Prefix => "prefix",
MatchingPolicy::Wildcard => "wildcard",
MatchingPolicy::Strict => "",
};
serializer.serialize_str(ser_str)
}
}
impl<'de> serde::Deserialize<'de> for MatchingPolicy {
fn deserialize<D>(deserializer: D) -> Result<MatchingPolicy, D::Error>
where
D: serde::Deserializer<'de>,
{
deserializer.deserialize_str(MatchingPolicyVisitor)
}
}
impl<'de> serde::de::Visitor<'de> for MatchingPolicyVisitor {
type Value = MatchingPolicy;
fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
formatter.write_str("matching policy for registration")
}
#[inline]
fn visit_str<E>(self, value: &str) -> Result<MatchingPolicy, E>
where
E: serde::de::Error,
{
match value {
"prefix" => Ok(MatchingPolicy::Prefix),
"wildcard" => Ok(MatchingPolicy::Wildcard),
x => Err(serde::de::Error::custom(format!(
"Invalid matching policy: {}",
x
))),
}
}
}
impl serde::Serialize for InvocationPolicy {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
let ser_str = match *self {
InvocationPolicy::Single => "single",
InvocationPolicy::RoundRobin => "roundrobin",
InvocationPolicy::Random => "random",
InvocationPolicy::First => "first",
InvocationPolicy::Last => "last",
};
serializer.serialize_str(ser_str)
}
}
impl<'de> serde::Deserialize<'de> for InvocationPolicy {
fn deserialize<D>(deserializer: D) -> Result<InvocationPolicy, D::Error>
where
D: serde::Deserializer<'de>,
{
deserializer.deserialize_str(InvocationPolicyVisitor)
}
}
impl<'de> serde::de::Visitor<'de> for InvocationPolicyVisitor {
type Value = InvocationPolicy;
fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
formatter.write_str("invocation policy for a procedure")
}
#[inline]
fn visit_str<E>(self, value: &str) -> Result<InvocationPolicy, E>
where
E: serde::de::Error,
{
match value {
"single" => Ok(InvocationPolicy::Single),
"roundrobin" => Ok(InvocationPolicy::RoundRobin),
"random" => Ok(InvocationPolicy::Random),
"first" => Ok(InvocationPolicy::First),
"last" => Ok(InvocationPolicy::Last),
x => Err(serde::de::Error::custom(format!(
"Invalid invocation policy: {}",
x
))),
}
}
}