From 15d6f3e2ee6f5f5bd280e794e441b5693810b2fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonah=20Br=C3=BCchert?= Date: Sat, 24 Feb 2024 23:22:55 +0100 Subject: [PATCH] motis-proxy: Format code --- motis-proxy/src/main.rs | 4 ++-- motis-proxy/src/rate_limit.rs | 17 +++++++++++------ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/motis-proxy/src/main.rs b/motis-proxy/src/main.rs index e9c1c2ea..5b14e3ff 100644 --- a/motis-proxy/src/main.rs +++ b/motis-proxy/src/main.rs @@ -127,7 +127,7 @@ enum StartType { OntripStationStart, /// The user is already on a train and wants to find connections from there. /// See [Ontrip Train Start](https://motis-project.de/docs/api/endpoint/intermodal.html#ontrip-train-start) in the MOTIS documentation. - OntripTrainStart + OntripTrainStart, } #[derive(Deserialize, Serialize, JsonSchema)] @@ -582,7 +582,7 @@ fn rocket() -> _ { .manage(IpRateLimit::new( NonZeroUsize::new(config.lru_rate_limit_entries) .expect("lru_rate_limit_entries must not be zero"), - config.routes_per_minute_limit + config.routes_per_minute_limit, )) .manage(config) .mount("/", routes) diff --git a/motis-proxy/src/rate_limit.rs b/motis-proxy/src/rate_limit.rs index e84505bf..7a651475 100644 --- a/motis-proxy/src/rate_limit.rs +++ b/motis-proxy/src/rate_limit.rs @@ -3,7 +3,12 @@ // SPDX-License-Identifier: AGPL-3.0-or-later use lru::LruCache; -use std::{net::IpAddr, num::NonZeroUsize, time::Duration, sync::{Arc, Mutex}}; +use std::{ + net::IpAddr, + num::NonZeroUsize, + sync::{Arc, Mutex}, + time::Duration, +}; use std::time::Instant; @@ -14,7 +19,7 @@ struct Inner { } pub struct IpRateLimit { - inner: Arc> + inner: Arc>, } impl IpRateLimit { @@ -24,7 +29,7 @@ impl IpRateLimit { requests: LruCache::new(size), rate_limit, last_cleared: Instant::now(), - })) + })), } } @@ -44,11 +49,11 @@ impl IpRateLimit { inner.requests.put(*ip, 1); } - // Check if ip has reached rate limit let rate_limit = inner.rate_limit; - inner.requests - .get(&ip) + inner + .requests + .get(ip) .map(|count| *count >= rate_limit) .unwrap_or(false) }