@@ -70,10 +70,12 @@ pub type BoxedProxyStorage = Box<dyn ProxyStoragePort>;
7070fn 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<()> {
136136use std:: collections:: HashMap ;
137137use tokio:: sync:: RwLock ;
138138
139- use std:: sync:: Arc ;
140139use crate :: types:: ProxyMetrics ;
140+ use std:: sync:: Arc ;
141141
142142type 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 ( ) ;
0 commit comments