Skip to content

Commit

Permalink
[clippy] Cargo fmt + clippy ^
Browse files Browse the repository at this point in the history
  • Loading branch information
didierofrivia committed Jun 23, 2023
1 parent 636a0d1 commit 44310d0
Showing 1 changed file with 28 additions and 27 deletions.
55 changes: 28 additions & 27 deletions limitador/src/storage/in_memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,49 +62,50 @@ impl CounterStorage for InMemoryStorage {
let mut limits_by_namespace = self.limits_for_namespace.write().unwrap();
let mut first_limited = None;

let mut process_counter = |counter: &mut Counter, value:i64, delta:i64 | -> Option<Authorization> {
if load_counters {
let remaining = counter.max_value() - (value + delta);
counter.set_remaining(remaining);
if first_limited.is_none() && remaining < 0 {
first_limited = Some(Authorization::Limited(
let mut process_counter =
|counter: &mut Counter, value: i64, delta: i64| -> Option<Authorization> {
if load_counters {
let remaining = counter.max_value() - (value + delta);
counter.set_remaining(remaining);
if first_limited.is_none() && remaining < 0 {
first_limited = Some(Authorization::Limited(
counter.limit().name().map(|n| n.to_owned()),
));
}
}
if !Self::counter_is_within_limits(counter, Some(&value), delta) {
return Some(Authorization::Limited(
counter.limit().name().map(|n| n.to_owned()),
));
}
}
if !Self::counter_is_within_limits(counter, Some(&value), delta) {
return Some(Authorization::Limited(
counter.limit().name().map(|n| n.to_owned()),
));
}
None
};
None
};

for counter in counters.iter_mut() {
if let Some(limits) = limits_by_namespace.get(counter.limit().namespace()) {
if let Some(counters) = limits.get(counter.limit()) {
if let Some(expiring_value) = counters.get(counter) {
let value = expiring_value.value();
if let Some(Authorization::Limited(counter_limited)) = process_counter(counter, value, delta) {
if let Some(Authorization::Limited(counter_limited)) =
process_counter(counter, value, delta)
{
if !load_counters {
return Ok(Authorization::Limited(
counter_limited,
));
return Ok(Authorization::Limited(counter_limited));
}
}
} else {
if let Some(limited) = process_counter(counter, 0, delta) {
if !load_counters { return Ok(limited); }
} else if let Some(limited) = process_counter(counter, 0, delta) {
if !load_counters {
return Ok(limited);
}
}
} else {
if let Some(limited) = process_counter(counter, 0, delta) {
if !load_counters { return Ok(limited); }
} else if let Some(limited) = process_counter(counter, 0, delta) {
if !load_counters {
return Ok(limited);
}
}
} else {
if let Some(limited) = process_counter(counter, 0, delta) {
if !load_counters { return Ok(limited); }
} else if let Some(limited) = process_counter(counter, 0, delta) {
if !load_counters {
return Ok(limited);
}
}
}
Expand Down

0 comments on commit 44310d0

Please sign in to comment.