Skip to content

Commit 113f9cb

Browse files
committed
style: apply rustfmt to stygian-proxy
1 parent dbb2f63 commit 113f9cb

File tree

3 files changed

+53
-24
lines changed

3 files changed

+53
-24
lines changed

crates/stygian-proxy/AGENTS.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ HTTP adapters). No external database required: the in-memory backend
1111
supports all production workloads; persistence adapters are optional and
1212
unlocked via feature flags.
1313

14-
1514
## Setup commands
1615

1716
- Build: `cargo build -p stygian-proxy --all-features`
@@ -30,7 +29,6 @@ unlocked via feature flags.
3029

3130
- Language: rust
3231

33-
3432
## Rules
3533

3634
- Rust edition 2024, stable toolchain (1.94.0).

crates/stygian-proxy/src/storage/mod.rs

Lines changed: 48 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,12 @@ pub type BoxedProxyStorage = Box<dyn ProxyStoragePort>;
7070
fn validate_proxy_url(url: &str) -> ProxyResult<()> {
7171
use crate::error::ProxyError;
7272

73-
let (scheme, rest) = url.split_once("://").ok_or_else(|| ProxyError::InvalidProxyUrl {
74-
url: url.to_owned(),
75-
reason: "missing scheme separator '://'".into(),
76-
})?;
73+
let (scheme, rest) = url
74+
.split_once("://")
75+
.ok_or_else(|| ProxyError::InvalidProxyUrl {
76+
url: url.to_owned(),
77+
reason: "missing scheme separator '://'".into(),
78+
})?;
7779

7880
match scheme {
7981
"http" | "https" => {}
@@ -83,7 +85,7 @@ fn validate_proxy_url(url: &str) -> ProxyResult<()> {
8385
return Err(ProxyError::InvalidProxyUrl {
8486
url: url.to_owned(),
8587
reason: format!("unsupported scheme '{other}'"),
86-
})
88+
});
8789
}
8890
}
8991

@@ -112,12 +114,10 @@ fn validate_proxy_url(url: &str) -> ProxyResult<()> {
112114
}
113115

114116
if !port_str.is_empty() {
115-
let port: u32 = port_str
116-
.parse()
117-
.map_err(|_| ProxyError::InvalidProxyUrl {
118-
url: url.to_owned(),
119-
reason: format!("non-numeric port '{port_str}'"),
120-
})?;
117+
let port: u32 = port_str.parse().map_err(|_| ProxyError::InvalidProxyUrl {
118+
url: url.to_owned(),
119+
reason: format!("non-numeric port '{port_str}'"),
120+
})?;
121121
if port == 0 || port > 65535 {
122122
return Err(ProxyError::InvalidProxyUrl {
123123
url: url.to_owned(),
@@ -136,8 +136,8 @@ fn validate_proxy_url(url: &str) -> ProxyResult<()> {
136136
use std::collections::HashMap;
137137
use tokio::sync::RwLock;
138138

139-
use std::sync::Arc;
140139
use crate::types::ProxyMetrics;
140+
use std::sync::Arc;
141141

142142
type StoreMap = HashMap<Uuid, (ProxyRecord, Arc<ProxyMetrics>)>;
143143

@@ -187,7 +187,10 @@ impl ProxyStoragePort for MemoryProxyStore {
187187
validate_proxy_url(&proxy.url)?;
188188
let record = ProxyRecord::new(proxy);
189189
let metrics = Arc::new(ProxyMetrics::default());
190-
self.inner.write().await.insert(record.id, (record.clone(), metrics));
190+
self.inner
191+
.write()
192+
.await
193+
.insert(record.id, (record.clone(), metrics));
191194
Ok(record)
192195
}
193196

@@ -201,7 +204,13 @@ impl ProxyStoragePort for MemoryProxyStore {
201204
}
202205

203206
async fn list(&self) -> ProxyResult<Vec<ProxyRecord>> {
204-
Ok(self.inner.read().await.values().map(|(r, _)| r.clone()).collect())
207+
Ok(self
208+
.inner
209+
.read()
210+
.await
211+
.values()
212+
.map(|(r, _)| r.clone())
213+
.collect())
205214
}
206215

207216
async fn get(&self, id: Uuid) -> ProxyResult<ProxyRecord> {
@@ -214,7 +223,13 @@ impl ProxyStoragePort for MemoryProxyStore {
214223
}
215224

216225
async fn list_with_metrics(&self) -> ProxyResult<Vec<(ProxyRecord, Arc<ProxyMetrics>)>> {
217-
Ok(self.inner.read().await.values().map(|(r, m)| (r.clone(), Arc::clone(m))).collect())
226+
Ok(self
227+
.inner
228+
.read()
229+
.await
230+
.values()
231+
.map(|(r, m)| (r.clone(), Arc::clone(m)))
232+
.collect())
218233
}
219234

220235
async fn update_metrics(&self, id: Uuid, success: bool, latency_ms: u64) -> ProxyResult<()> {
@@ -226,7 +241,9 @@ impl ProxyStoragePort for MemoryProxyStore {
226241
.await
227242
.get(&id)
228243
.map(|(_, m)| Arc::clone(m))
229-
.ok_or_else(|| crate::error::ProxyError::StorageError(format!("proxy {id} not found")))?;
244+
.ok_or_else(|| {
245+
crate::error::ProxyError::StorageError(format!("proxy {id} not found"))
246+
})?;
230247

231248
// Lock released before the atomic updates — no long critical section.
232249
metrics.requests_total.fetch_add(1, Ordering::Relaxed);
@@ -235,7 +252,9 @@ impl ProxyStoragePort for MemoryProxyStore {
235252
} else {
236253
metrics.failures.fetch_add(1, Ordering::Relaxed);
237254
}
238-
metrics.total_latency_ms.fetch_add(latency_ms, Ordering::Relaxed);
255+
metrics
256+
.total_latency_ms
257+
.fetch_add(latency_ms, Ordering::Relaxed);
239258
Ok(())
240259
}
241260
}
@@ -280,22 +299,31 @@ mod tests {
280299
async fn invalid_url_rejected() {
281300
let store = MemoryProxyStore::default();
282301
let err = store.add(make_proxy("not-a-url")).await.unwrap_err();
283-
assert!(matches!(err, crate::error::ProxyError::InvalidProxyUrl { .. }));
302+
assert!(matches!(
303+
err,
304+
crate::error::ProxyError::InvalidProxyUrl { .. }
305+
));
284306
}
285307

286308
#[tokio::test]
287309
async fn invalid_url_empty_host() {
288310
let store = MemoryProxyStore::default();
289311
let err = store.add(make_proxy("http://:8080")).await.unwrap_err();
290-
assert!(matches!(err, crate::error::ProxyError::InvalidProxyUrl { .. }));
312+
assert!(matches!(
313+
err,
314+
crate::error::ProxyError::InvalidProxyUrl { .. }
315+
));
291316
}
292317

293318
#[tokio::test]
294319
async fn concurrent_metrics_updates() {
295320
use tokio::task::JoinSet;
296321

297322
let store = Arc::new(MemoryProxyStore::default());
298-
let record = store.add(make_proxy("http://proxy.test:3128")).await.unwrap();
323+
let record = store
324+
.add(make_proxy("http://proxy.test:3128"))
325+
.await
326+
.unwrap();
299327
let id = record.id;
300328

301329
let mut tasks = JoinSet::new();

crates/stygian-proxy/src/strategy/round_robin.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::sync::atomic::{AtomicUsize, Ordering};
55
use async_trait::async_trait;
66

77
use crate::error::ProxyResult;
8-
use crate::strategy::{healthy_candidates, ProxyCandidate, RotationStrategy};
8+
use crate::strategy::{ProxyCandidate, RotationStrategy, healthy_candidates};
99

1010
/// Cycles through healthy proxies in order, distributing load evenly.
1111
///
@@ -47,7 +47,10 @@ impl RotationStrategy for RoundRobinStrategy {
4747
if healthy.is_empty() {
4848
return Err(ProxyError::AllProxiesUnhealthy);
4949
}
50-
let idx = self.counter.fetch_add(1, Ordering::Relaxed).wrapping_rem(healthy.len());
50+
let idx = self
51+
.counter
52+
.fetch_add(1, Ordering::Relaxed)
53+
.wrapping_rem(healthy.len());
5154
Ok(healthy[idx])
5255
}
5356
}

0 commit comments

Comments
 (0)