Skip to content

Commit df62b0e

Browse files
committed
fix clippy warnings/errors
Signed-off-by: Eren Atas <[email protected]>
1 parent 93daad9 commit df62b0e

File tree

7 files changed

+26
-21
lines changed

7 files changed

+26
-21
lines changed

crates/flagd/src/cache/service.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,9 @@ impl CacheKey {
159159
}
160160
}
161161

162+
/// Type alias for the thread-safe cache implementation
163+
type SharedCache<V> = Arc<RwLock<Box<dyn Cache<CacheKey, CacheEntry<V>>>>>;
164+
162165
/// Service managing cache operations and lifecycle
163166
#[derive(Debug)]
164167
pub struct CacheService<V>
@@ -170,7 +173,7 @@ where
170173
/// Time-to-live configuration for cache entries
171174
ttl: Option<Duration>,
172175
/// The underlying cache implementation
173-
cache: Arc<RwLock<Box<dyn Cache<CacheKey, CacheEntry<V>>>>>,
176+
cache: SharedCache<V>,
174177
}
175178

176179
impl<V> CacheService<V>
@@ -218,11 +221,11 @@ where
218221
let mut cache = self.cache.write().await;
219222

220223
if let Some(entry) = cache.get(&cache_key) {
221-
if let Some(ttl) = self.ttl {
222-
if entry.created_at.elapsed() > ttl {
223-
cache.remove(&cache_key);
224-
return None;
225-
}
224+
if let Some(ttl) = self.ttl
225+
&& entry.created_at.elapsed() > ttl
226+
{
227+
cache.remove(&cache_key);
228+
return None;
226229
}
227230
return Some(entry.value.clone());
228231
}

crates/flagd/src/lib.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -470,11 +470,10 @@ impl FlagdProvider {
470470
context: &EvaluationContext,
471471
value_converter: impl Fn(Value) -> Option<T>,
472472
) -> Option<T> {
473-
if let Some(cache) = &self.cache {
474-
if let Some(cached_value) = cache.get(flag_key, context).await {
473+
if let Some(cache) = &self.cache
474+
&& let Some(cached_value) = cache.get(flag_key, context).await {
475475
return value_converter(cached_value);
476476
}
477-
}
478477
None
479478
}
480479
}

crates/flagd/src/resolver/in_process/model/flag_parser.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ impl FlagParser {
2121
let flag_set_metadata = obj
2222
.get("metadata")
2323
.and_then(|v| v.as_object())
24-
.map(|m| Self::convert_map_to_hashmap(m))
24+
.map(Self::convert_map_to_hashmap)
2525
.unwrap_or_default();
2626

2727
let mut flag_map = HashMap::new();

crates/flagd/src/resolver/in_process/resolver/file.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,14 @@ impl FileResolver {
5050
value_converter: impl Fn(&serde_json::Value) -> Option<T>,
5151
type_name: &str,
5252
) -> Result<ResolutionDetails<T>, EvaluationError> {
53-
if let Some(cache) = &self.cache {
54-
if let Some(cached_value) = cache.get(flag_key, context).await {
53+
if let Some(cache) = &self.cache
54+
&& let Some(cached_value) = cache.get(flag_key, context).await {
5555
debug!("Cache hit for key: {}", flag_key);
5656
let json_value = cached_value.to_serde_json();
5757
if let Some(value) = value_converter(&json_value) {
5858
return Ok(ResolutionDetails::new(value));
5959
}
6060
}
61-
}
6261

6362
let query_result = self.store.get_flag(flag_key).await;
6463

crates/flagd/src/resolver/in_process/resolver/grpc.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,10 @@ impl InProcessResolver {
8585
context: &EvaluationContext,
8686
value_converter: impl Fn(&OpenFeatureValue) -> Option<T>,
8787
) -> Option<T> {
88-
if let Some(cache) = &self.cache {
89-
if let Some(cached_value) = cache.get(flag_key, context).await {
88+
if let Some(cache) = &self.cache
89+
&& let Some(cached_value) = cache.get(flag_key, context).await {
9090
return value_converter(&cached_value);
9191
}
92-
}
9392
None
9493
}
9594

@@ -117,7 +116,7 @@ impl InProcessResolver {
117116
OpenFeatureValue::Array(arr) => {
118117
// Convert OpenFeature array to JsonValue array
119118
let json_array =
120-
JsonValue::Array(arr.iter().map(|v| convert_to_json_value(v)).collect());
119+
JsonValue::Array(arr.iter().map(convert_to_json_value).collect());
121120
value_converter(&json_array)
122121
}
123122
})
@@ -309,7 +308,7 @@ fn convert_to_json_value(value: &OpenFeatureValue) -> JsonValue {
309308
OpenFeatureValue::Float(f) => JsonValue::Number(serde_json::Number::from_f64(*f).unwrap()),
310309
OpenFeatureValue::Struct(s) => convert_struct_to_json(s),
311310
OpenFeatureValue::Array(arr) => {
312-
JsonValue::Array(arr.iter().map(|v| convert_to_json_value(v)).collect())
311+
JsonValue::Array(arr.iter().map(convert_to_json_value).collect())
313312
}
314313
}
315314
}

crates/flagd/src/resolver/in_process/targeting/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ pub struct Operator {
1414
logic: Arc<DataLogic>,
1515
}
1616

17+
impl Default for Operator {
18+
fn default() -> Self {
19+
Self::new()
20+
}
21+
}
22+
1723
impl Operator {
1824
pub fn new() -> Self {
1925
// Create a new DataLogic instance

crates/flagd/src/resolver/rpc.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,8 @@ impl RpcResolver {
158158
let mut endpoint = upstream_config.endpoint().clone();
159159

160160
// Extend support for envoy names resolution
161-
if let Some(uri) = &options.target_uri {
162-
if uri.starts_with("envoy://") {
161+
if let Some(uri) = &options.target_uri
162+
&& uri.starts_with("envoy://") {
163163
// Expected format: envoy://<host:port>/<desired_authority>
164164
let without_prefix = uri.trim_start_matches("envoy://");
165165
let segments: Vec<&str> = without_prefix.split('/').collect();
@@ -171,7 +171,6 @@ impl RpcResolver {
171171
endpoint = endpoint.origin(authority_uri);
172172
}
173173
}
174-
}
175174

176175
let channel = endpoint
177176
.timeout(Duration::from_millis(options.deadline_ms as u64))

0 commit comments

Comments
 (0)