From 359bb937b298fda8bdc2ed10582dbdf70576bf08 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 13 Jul 2026 14:40:05 -0500 Subject: [PATCH] style(sidecar): apply rustfmt Format the sidecar source with `cargo fmt` so the new `cargo fmt --check` CI gate passes on the first run. No behavior change. Co-Authored-By: Claude Opus 4.8 Claude-Session: https://claude.ai/code/session_0114TpmrNW4wNXsHq5CR72jQ --- sidecar/src/config.rs | 5 ++++- sidecar/src/main.rs | 6 +++++- sidecar/src/rpc.rs | 5 +---- sidecar/src/store.rs | 11 ++++++++--- sidecar/src/web.rs | 29 ++++++++++++++++++++--------- 5 files changed, 38 insertions(+), 18 deletions(-) diff --git a/sidecar/src/config.rs b/sidecar/src/config.rs index 984f640..846fd3a 100644 --- a/sidecar/src/config.rs +++ b/sidecar/src/config.rs @@ -142,7 +142,10 @@ fn persist_token(path: &str, token: &str) -> anyhow::Result<()> { let text = fs::read_to_string(path)?; let line = format!("auth_token = \"{token}\""); - if text.lines().any(|l| l.trim_start().starts_with("auth_token")) { + if text + .lines() + .any(|l| l.trim_start().starts_with("auth_token")) + { let out: String = text .lines() .map(|l| { diff --git a/sidecar/src/main.rs b/sidecar/src/main.rs index 5bf2e41..61d3066 100644 --- a/sidecar/src/main.rs +++ b/sidecar/src/main.rs @@ -96,7 +96,11 @@ async fn main() -> anyhow::Result<()> { // Persist, then broadcast. `pong` and `ws.hello` are ephemeral chatter, not history. if ev.kind != "pong" { - let t = ev.value.get("t").and_then(|v| v.as_i64()).unwrap_or_else(now_ms); + let t = ev + .value + .get("t") + .and_then(|v| v.as_i64()) + .unwrap_or_else(now_ms); let text = ev.value.to_string(); if let Err(e) = event_store.insert_event(t, &ev.kind, &text).await { tracing::warn!(error = %e, "failed to persist event"); diff --git a/sidecar/src/rpc.rs b/sidecar/src/rpc.rs index d4b09be..2f120c9 100644 --- a/sidecar/src/rpc.rs +++ b/sidecar/src/rpc.rs @@ -56,10 +56,7 @@ impl Rpc { ) -> Result { let (tx, rx) = oneshot::channel(); - self.pending - .lock() - .await - .insert(corr_val.to_string(), tx); + self.pending.lock().await.insert(corr_val.to_string(), tx); if !shard.send(command.to_string()).await { self.pending.lock().await.remove(corr_val); diff --git a/sidecar/src/store.rs b/sidecar/src/store.rs index 945f166..64ad25c 100644 --- a/sidecar/src/store.rs +++ b/sidecar/src/store.rs @@ -21,8 +21,8 @@ pub struct Store { impl Store { /// Opens (creating if absent) the SQLite database and ensures the schema exists. pub async fn open(path: &str) -> anyhow::Result { - let opts = SqliteConnectOptions::from_str(&format!("sqlite://{path}"))? - .create_if_missing(true); + let opts = + SqliteConnectOptions::from_str(&format!("sqlite://{path}"))?.create_if_missing(true); let pool = SqlitePoolOptions::new() .max_connections(4) @@ -78,7 +78,12 @@ impl Store { self.recent(Some("economy.supply"), limit).await } - pub async fn record_link(&self, account: &str, website_user_id: &str, t: i64) -> anyhow::Result<()> { + pub async fn record_link( + &self, + account: &str, + website_user_id: &str, + t: i64, + ) -> anyhow::Result<()> { sqlx::query( "INSERT INTO links (account, website_user_id, linked_t) VALUES (?, ?, ?) ON CONFLICT(account) DO UPDATE SET website_user_id = excluded.website_user_id, linked_t = excluded.linked_t", diff --git a/sidecar/src/web.rs b/sidecar/src/web.rs index 4f0c9dd..e8675e3 100644 --- a/sidecar/src/web.rs +++ b/sidecar/src/web.rs @@ -123,7 +123,8 @@ fn iso_ms(ms: i64) -> Option { if ms <= 0 { return None; } - chrono::DateTime::from_timestamp_millis(ms).map(|dt| dt.format("%Y-%m-%dT%H:%M:%SZ").to_string()) + chrono::DateTime::from_timestamp_millis(ms) + .map(|dt| dt.format("%Y-%m-%dT%H:%M:%SZ").to_string()) } // ---- gate: protocol check + auth ---- @@ -174,8 +175,15 @@ async fn gate(State(st): State, req: Request, next: Next) -> Response fn extract_token(req: &Request) -> Option { // Authorization: Bearer - if let Some(v) = req.headers().get("authorization").and_then(|h| h.to_str().ok()) { - if let Some(rest) = v.strip_prefix("Bearer ").or_else(|| v.strip_prefix("bearer ")) { + if let Some(v) = req + .headers() + .get("authorization") + .and_then(|h| h.to_str().ok()) + { + if let Some(rest) = v + .strip_prefix("Bearer ") + .or_else(|| v.strip_prefix("bearer ")) + { return Some(rest.trim().to_string()); } } @@ -349,7 +357,10 @@ async fn page_respond( Path(id): Path, Json(body): Json, ) -> impl IntoResponse { - let message = body.get("message").and_then(|m| m.as_str()).unwrap_or_default(); + let message = body + .get("message") + .and_then(|m| m.as_str()) + .unwrap_or_default(); if message.trim().is_empty() { return ( StatusCode::BAD_REQUEST, @@ -439,7 +450,10 @@ async fn vendors(State(st): State, Path(account): Path) -> imp /// Body: {"code":"AB12CD","websiteUserId":"9931"}. Correlated on `code`. async fn link_confirm(State(st): State, Json(body): Json) -> impl IntoResponse { - let code = body.get("code").and_then(|c| c.as_str()).unwrap_or_default(); + let code = body + .get("code") + .and_then(|c| c.as_str()) + .unwrap_or_default(); let web_id = body .get("websiteUserId") .and_then(|w| w.as_str()) @@ -501,10 +515,7 @@ async fn towncrier_add(State(st): State, Json(body): Json) -> i respond(st.rpc.call(&st.shard, cmd, &id).await) } -async fn towncrier_remove( - State(st): State, - Path(id): Path, -) -> impl IntoResponse { +async fn towncrier_remove(State(st): State, Path(id): Path) -> impl IntoResponse { let cmd = json!({"kind":"towncrier.remove","id":id}); respond(st.rpc.call(&st.shard, cmd, &id).await) }