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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
use crate::Value;
use serde_repr::Deserialize_repr;
use std::fmt::{Display, Formatter};
/// Describes the internal state of the [`crate::Client`].
pub enum ClientCacheState {
/// The SDK has no feature flag data neither from the cache nor from the ConfigCat CDN.
NoFlagData,
/// The SDK runs with local only feature flag data.
HasLocalOverrideFlagDataOnly,
/// The SDK has feature flag data to work with only from the cache.
HasCachedFlagDataOnly,
/// The SDK works with the latest feature flag data received from the ConfigCat CDN.
HasUpToDateFlagData,
}
/// Describes the location of your feature flag and setting data within the ConfigCat CDN.
#[derive(Clone, PartialEq, Debug)]
pub enum DataGovernance {
/// Select this if your feature flags are published to all global CDN nodes.
Global,
/// Select this if your feature flags are published to CDN nodes only in the EU.
EU,
}
#[derive(Debug, Deserialize_repr, PartialEq, Clone)]
#[repr(u8)]
pub enum RedirectMode {
No,
Should,
Force,
}
/// The type of the feature flag or setting.
#[derive(Debug, Clone, Deserialize_repr)]
#[repr(u8)]
pub enum SettingType {
/// The on/off type (feature flag).
Bool = 0,
/// The text setting type.
String = 1,
/// The whole number setting type.
Int = 2,
/// The decimal number setting type.
Float = 3,
}
impl From<&Value> for SettingType {
fn from(value: &Value) -> Self {
match value {
Value::Bool(_) => SettingType::Bool,
Value::Int(_) => SettingType::Int,
Value::Float(_) => SettingType::Float,
Value::String(_) => SettingType::String,
}
}
}
impl Display for SettingType {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
SettingType::Bool => f.write_str("Bool"),
SettingType::String => f.write_str("String"),
SettingType::Int => f.write_str("Int"),
SettingType::Float => f.write_str("Float"),
}
}
}
/// Segment comparison operator used during the evaluation process.
#[derive(Debug, PartialEq, Deserialize_repr)]
#[repr(u8)]
pub enum SegmentComparator {
/// Checks whether the conditions of the specified segment are evaluated to true.
IsIn = 0,
/// Checks whether the conditions of the specified segment are evaluated to false.
IsNotIn = 1,
}
impl Display for SegmentComparator {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
SegmentComparator::IsIn => f.write_str("IS IN SEGMENT"),
SegmentComparator::IsNotIn => f.write_str("IS NOT IN SEGMENT"),
}
}
}
/// Prerequisite flag comparison operator used during the evaluation process.
#[derive(Debug, PartialEq, Deserialize_repr)]
#[repr(u8)]
pub enum PrerequisiteFlagComparator {
/// Checks whether the evaluated value of the specified prerequisite flag is equal to the comparison value.
Eq = 0,
/// Checks whether the evaluated value of the specified prerequisite flag is not equal to the comparison value.
NotEq = 1,
}
impl Display for PrerequisiteFlagComparator {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
PrerequisiteFlagComparator::Eq => f.write_str("EQUALS"),
PrerequisiteFlagComparator::NotEq => f.write_str("NOT EQUALS"),
}
}
}
/// User Object attribute comparison operator used during the evaluation process.
#[derive(Debug, PartialEq, Deserialize_repr)]
#[repr(u8)]
pub enum UserComparator {
/// Checks whether the comparison attribute is equal to any of the comparison values.
OneOf = 0,
/// Checks whether the comparison attribute is not equal to any of the comparison values.
NotOneOf = 1,
/// Checks whether the comparison attribute contains any comparison values as a substring.
Contains = 2,
/// Checks whether the comparison attribute does not contain any comparison values as a substring.
NotContains = 3,
/// Checks whether the comparison attribute interpreted as a semantic version is equal to any of the comparison values.
OneOfSemver = 4,
/// Checks whether the comparison attribute interpreted as a semantic version is not equal to any of the comparison values.
NotOneOfSemver = 5,
/// Checks whether the comparison attribute interpreted as a semantic version is less than the comparison value.
LessSemver = 6,
/// Checks whether the comparison attribute interpreted as a semantic version is less than or equal to the comparison value.
LessEqSemver = 7,
/// Checks whether the comparison attribute interpreted as a semantic version is greater than the comparison value.
GreaterSemver = 8,
/// Checks whether the comparison attribute interpreted as a semantic version is greater than or equal to the comparison value.
GreaterEqSemver = 9,
/// Checks whether the comparison attribute interpreted as a decimal number is equal to the comparison value.
EqNum = 10,
/// Checks whether the comparison attribute interpreted as a decimal number is not equal to the comparison value.
NotEqNum = 11,
/// Checks whether the comparison attribute interpreted as a decimal number is less than the comparison value.
LessNum = 12,
/// Checks whether the comparison attribute interpreted as a decimal number is less than or equal to the comparison value.
LessEqNum = 13,
/// Checks whether the comparison attribute interpreted as a decimal number is greater than the comparison value.
GreaterNum = 14,
/// Checks whether the comparison attribute interpreted as a decimal number is greater than or equal to the comparison value.
GreaterEqNum = 15,
/// Checks whether the comparison attribute is equal to any of the comparison values (where the comparison is performed using the salted SHA256 hashes of the values).
OneOfHashed = 16,
/// Checks whether the comparison attribute is not equal to any of the comparison values (where the comparison is performed using the salted SHA256 hashes of the values).
NotOneOfHashed = 17,
/// Checks whether the comparison attribute interpreted as the seconds elapsed since Unix Epoch is less than the comparison value.
BeforeDateTime = 18,
/// Checks whether the comparison attribute interpreted as the seconds elapsed since Unix Epoch is greater than the comparison value.
AfterDateTime = 19,
/// Checks whether the comparison attribute is equal to the comparison value (where the comparison is performed using the salted SHA256 hashes of the values).
EqHashed = 20,
/// Checks whether the comparison attribute is not equal to the comparison value (where the comparison is performed using the salted SHA256 hashes of the values).
NotEqHashed = 21,
/// Checks whether the comparison attribute starts with any of the comparison values (where the comparison is performed using the salted SHA256 hashes of the values).
StartsWithAnyOfHashed = 22,
/// Checks whether the comparison attribute does not start with any of the comparison values (where the comparison is performed using the salted SHA256 hashes of the values).
NotStartsWithAnyOfHashed = 23,
/// Checks whether the comparison attribute ends with any of the comparison values (where the comparison is performed using the salted SHA256 hashes of the values).
EndsWithAnyOfHashed = 24,
/// Checks whether the comparison attribute does not end with any of the comparison values (where the comparison is performed using the salted SHA256 hashes of the values).
NotEndsWithAnyOfHashed = 25,
/// Checks whether the comparison attribute interpreted as a string list contains any of the comparison values (where the comparison is performed using the salted SHA256 hashes of the values).
ArrayContainsAnyOfHashed = 26,
/// Checks whether the comparison attribute interpreted as a string list does not contain any of the comparison values (where the comparison is performed using the salted SHA256 hashes of the values).
ArrayNotContainsAnyOfHashed = 27,
/// Checks whether the comparison attribute is equal to the comparison value.
Eq = 28,
/// Checks whether the comparison attribute is not equal to the comparison value.
NotEq = 29,
/// Checks whether the comparison attribute starts with any of the comparison values.
StartsWithAnyOf = 30,
/// Checks whether the comparison attribute does not start with any of the comparison values.
NotStartsWithAnyOf = 31,
/// Checks whether the comparison attribute ends with any of the comparison values.
EndsWithAnyOf = 32,
/// Checks whether the comparison attribute does not end with any of the comparison values.
NotEndsWithAnyOf = 33,
/// Checks whether the comparison attribute interpreted as a string list contains any of the comparison values.
ArrayContainsAnyOf = 34,
/// Checks whether the comparison attribute interpreted as a string list does not contain any of the comparison values.
ArrayNotContainsAnyOf = 35,
}
impl Display for UserComparator {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
UserComparator::Contains => f.write_str("CONTAINS ANY OF"),
UserComparator::NotContains => f.write_str("NOT CONTAINS ANY OF"),
UserComparator::OneOfSemver | UserComparator::OneOfHashed | UserComparator::OneOf => {
f.write_str("IS ONE OF")
}
UserComparator::NotOneOfSemver
| UserComparator::NotOneOf
| UserComparator::NotOneOfHashed => f.write_str("IS NOT ONE OF"),
UserComparator::LessSemver | UserComparator::LessNum => f.write_str("<"),
UserComparator::LessEqSemver | UserComparator::LessEqNum => f.write_str("<="),
UserComparator::GreaterSemver | UserComparator::GreaterNum => f.write_str(">"),
UserComparator::GreaterEqSemver | UserComparator::GreaterEqNum => f.write_str(">="),
UserComparator::EqNum => f.write_str("="),
UserComparator::NotEqNum => f.write_str("!="),
UserComparator::BeforeDateTime => f.write_str("BEFORE"),
UserComparator::AfterDateTime => f.write_str("AFTER"),
UserComparator::EqHashed | UserComparator::Eq => f.write_str("EQUALS"),
UserComparator::NotEqHashed | UserComparator::NotEq => f.write_str("NOT EQUALS"),
UserComparator::StartsWithAnyOfHashed | UserComparator::StartsWithAnyOf => {
f.write_str("STARTS WITH ANY OF")
}
UserComparator::NotStartsWithAnyOfHashed | UserComparator::NotStartsWithAnyOf => {
f.write_str("NOT STARTS WITH ANY OF")
}
UserComparator::EndsWithAnyOfHashed | UserComparator::EndsWithAnyOf => {
f.write_str("ENDS WITH ANY OF")
}
UserComparator::NotEndsWithAnyOfHashed | UserComparator::NotEndsWithAnyOf => {
f.write_str("NOT ENDS WITH ANY OF")
}
UserComparator::ArrayContainsAnyOfHashed | UserComparator::ArrayContainsAnyOf => {
f.write_str("ARRAY CONTAINS ANY OF")
}
UserComparator::ArrayNotContainsAnyOfHashed | UserComparator::ArrayNotContainsAnyOf => {
f.write_str("ARRAY NOT CONTAINS ANY OF")
}
}
}
}
impl UserComparator {
pub(crate) fn is_sensitive(&self) -> bool {
matches!(
self,
UserComparator::OneOfHashed
| UserComparator::NotOneOfHashed
| UserComparator::EqHashed
| UserComparator::NotEqHashed
| UserComparator::StartsWithAnyOfHashed
| UserComparator::NotStartsWithAnyOfHashed
| UserComparator::EndsWithAnyOfHashed
| UserComparator::NotEndsWithAnyOfHashed
| UserComparator::ArrayContainsAnyOfHashed
| UserComparator::ArrayNotContainsAnyOfHashed
)
}
pub(crate) fn is_date(&self) -> bool {
matches!(
self,
UserComparator::AfterDateTime | UserComparator::BeforeDateTime
)
}
pub(crate) fn is_starts_with(&self) -> bool {
matches!(
self,
UserComparator::StartsWithAnyOf
| UserComparator::StartsWithAnyOfHashed
| UserComparator::NotStartsWithAnyOf
| UserComparator::NotStartsWithAnyOfHashed
)
}
}