Skip to content

Commit ea7ce59

Browse files
committed
style: use inline format args for improved readability
Replace format!("{}", var) with format!("{var}") in cache, backend, server, and cli crates. This follows the Rust 2021 edition style.
1 parent 0fec382 commit ea7ce59

7 files changed

Lines changed: 18 additions & 15 deletions

File tree

crates/backend/src/http.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ impl HttpBackend {
8484
response
8585
.json()
8686
.await
87-
.map_err(|e| RoxyError::Internal(format!("failed to parse response: {}", e)))
87+
.map_err(|e| RoxyError::Internal(format!("failed to parse response: {e}")))
8888
}
8989
}
9090

crates/cache/src/compressed.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ pub struct CompressedCache<C> {
2727

2828
impl<C: Cache> CompressedCache<C> {
2929
/// Create a new compressed cache with default compression quality.
30+
#[must_use]
3031
pub fn new(inner: C) -> Self {
3132
Self::with_quality(inner, DEFAULT_QUALITY)
3233
}
@@ -36,6 +37,7 @@ impl<C: Cache> CompressedCache<C> {
3637
/// # Arguments
3738
/// * `inner` - The inner cache to wrap
3839
/// * `quality` - Brotli compression quality (0-11, where 11 is best compression)
40+
#[must_use]
3941
pub fn with_quality(inner: C, quality: u32) -> Self {
4042
Self { inner, quality: quality.min(11) }
4143
}
@@ -50,7 +52,7 @@ impl<C: Cache> CompressedCache<C> {
5052
self.quality,
5153
DEFAULT_LG_WINDOW_SIZE,
5254
);
53-
writer.write_all(data).map_err(|e| CacheError(format!("compression failed: {}", e)))?;
55+
writer.write_all(data).map_err(|e| CacheError(format!("compression failed: {e}")))?;
5456
}
5557
Ok(compressed)
5658
}
@@ -61,7 +63,7 @@ impl<C: Cache> CompressedCache<C> {
6163
let mut decompressor = brotli::Decompressor::new(data, 4096);
6264
decompressor
6365
.read_to_end(&mut decompressed)
64-
.map_err(|e| CacheError(format!("decompression failed: {}", e)))?;
66+
.map_err(|e| CacheError(format!("decompression failed: {e}")))?;
6567
Ok(decompressed)
6668
}
6769
}

crates/cache/src/memory.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ impl std::fmt::Debug for MemoryCache {
4040
impl Cache for MemoryCache {
4141
async fn get(&self, key: &str) -> Result<Option<Bytes>, CacheError> {
4242
let mut cache =
43-
self.cache.lock().map_err(|e| CacheError(format!("lock poisoned: {}", e)))?;
43+
self.cache.lock().map_err(|e| CacheError(format!("lock poisoned: {e}")))?;
4444

4545
if let Some(entry) = cache.get(key) {
4646
if entry.expires_at > Instant::now() {
@@ -54,7 +54,7 @@ impl Cache for MemoryCache {
5454

5555
async fn put(&self, key: &str, value: Bytes, ttl: Duration) -> Result<(), CacheError> {
5656
let mut cache =
57-
self.cache.lock().map_err(|e| CacheError(format!("lock poisoned: {}", e)))?;
57+
self.cache.lock().map_err(|e| CacheError(format!("lock poisoned: {e}")))?;
5858

5959
let entry = CacheEntry { value, expires_at: Instant::now() + ttl };
6060

@@ -64,7 +64,7 @@ impl Cache for MemoryCache {
6464

6565
async fn delete(&self, key: &str) -> Result<(), CacheError> {
6666
let mut cache =
67-
self.cache.lock().map_err(|e| CacheError(format!("lock poisoned: {}", e)))?;
67+
self.cache.lock().map_err(|e| CacheError(format!("lock poisoned: {e}")))?;
6868

6969
cache.pop(key);
7070
Ok(())

crates/cache/src/redis.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ impl RedisCache {
2626
/// Returns a `CacheError` if the URL is invalid or connection cannot be established.
2727
pub fn new(url: &str) -> Result<Self, CacheError> {
2828
let client =
29-
Client::open(url).map_err(|e| CacheError(format!("failed to create client: {}", e)))?;
29+
Client::open(url).map_err(|e| CacheError(format!("failed to create client: {e}")))?;
3030
Ok(Self { client })
3131
}
3232

@@ -35,7 +35,7 @@ impl RedisCache {
3535
self.client
3636
.get_multiplexed_async_connection()
3737
.await
38-
.map_err(|e| CacheError(format!("connection error: {}", e)))
38+
.map_err(|e| CacheError(format!("connection error: {e}")))
3939
}
4040
}
4141

@@ -44,7 +44,7 @@ impl Cache for RedisCache {
4444
let mut conn = self.get_connection().await?;
4545

4646
let result: Option<Vec<u8>> =
47-
conn.get(key).await.map_err(|e| CacheError(format!("get error: {}", e)))?;
47+
conn.get(key).await.map_err(|e| CacheError(format!("get error: {e}")))?;
4848

4949
Ok(result.map(Bytes::from))
5050
}
@@ -58,15 +58,15 @@ impl Cache for RedisCache {
5858
// Use SETEX for atomic set with expiration
5959
conn.set_ex::<_, _, ()>(key, value.as_ref(), ttl_secs)
6060
.await
61-
.map_err(|e| CacheError(format!("put error: {}", e)))?;
61+
.map_err(|e| CacheError(format!("put error: {e}")))?;
6262

6363
Ok(())
6464
}
6565

6666
async fn delete(&self, key: &str) -> Result<(), CacheError> {
6767
let mut conn = self.get_connection().await?;
6868

69-
conn.del::<_, ()>(key).await.map_err(|e| CacheError(format!("delete error: {}", e)))?;
69+
conn.del::<_, ()>(key).await.map_err(|e| CacheError(format!("delete error: {e}")))?;
7070

7171
Ok(())
7272
}

crates/cache/src/rpc_cache.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ impl<C: Cache> RpcCache<C> {
3636
///
3737
/// This initializes the cache with sensible default policies for common
3838
/// Ethereum JSON-RPC methods.
39+
#[must_use]
3940
pub fn new(inner: C) -> Self {
4041
let mut policies = HashMap::new();
4142

crates/cli/src/server.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub async fn run_server(app: roxy_server::Router, config: &RoxyConfig) -> Result
5353
let addr = format!("{}:{}", config.server.host, config.server.port);
5454
let listener = tokio::net::TcpListener::bind(&addr)
5555
.await
56-
.wrap_err_with(|| format!("failed to bind to {}", addr))?;
56+
.wrap_err_with(|| format!("failed to bind to {addr}"))?;
5757

5858
info!(address = %addr, "Roxy RPC proxy listening");
5959

@@ -63,7 +63,7 @@ pub async fn run_server(app: roxy_server::Router, config: &RoxyConfig) -> Result
6363
let metrics_addr = format!("{}:{}", config.metrics.host, config.metrics.port);
6464
let metrics_listener = tokio::net::TcpListener::bind(&metrics_addr)
6565
.await
66-
.wrap_err_with(|| format!("failed to bind metrics server to {}", metrics_addr))?;
66+
.wrap_err_with(|| format!("failed to bind metrics server to {metrics_addr}"))?;
6767

6868
info!(address = %metrics_addr, "Metrics server listening");
6969

crates/server/src/websocket.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ async fn handle_message(
527527
Ok(req) => req,
528528
Err(e) => {
529529
let response =
530-
WsResponse::error(serde_json::Value::Null, -32700, format!("Parse error: {}", e));
530+
WsResponse::error(serde_json::Value::Null, -32700, format!("Parse error: {e}"));
531531
return serde_json::to_string(&response).ok();
532532
}
533533
};
@@ -579,7 +579,7 @@ async fn handle_subscribe(
579579
return WsResponse::error(
580580
request.id.clone(),
581581
-32602,
582-
format!("Unknown subscription type: {}", subscription_type),
582+
format!("Unknown subscription type: {subscription_type}"),
583583
);
584584
}
585585
}

0 commit comments

Comments
 (0)