Server overhaul: clear clippy::pedantic wins

Taken from a -W clippy::pedantic scan, no allow added: map_or/map_or_else, method references instead of closures,
clone_from, write! instead of push_str(format!), borrowed Option<&str>, push_of without a needless Option, the
envelope's entity moved instead of cloned, the scheduler's plan() no longer a needless async fn (its doc now says
what it does on failure), sort_unstable, digit separators and inline format args in tests. Not taken: missing
# Errors/# Panics docs, must_use, doc backticks, assert!(x.is_empty()) in tests, too_many_lines.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TQd3pEP9UeN2uifbHknQ7B
This commit is contained in:
2026-10-18 22:33:31 +02:00
parent 8cb42f85a9
commit c942d73c66
18 changed files with 56 additions and 43 deletions
+11 -8
View File
@@ -57,7 +57,7 @@ fn canonical_uuid(value: Option<&Value>) -> Option<Uuid> {
.filter(|id| id.hyphenated().to_string() == text)
}
fn envelope(index: usize, raw: Value) -> Result<Envelope, AppError> {
fn envelope(index: usize, mut raw: Value) -> Result<Envelope, AppError> {
let bad = |what: &str| {
AppError::invalid_request(format!("mutations[{index}]: {what}")).with_field("mutations")
};
@@ -68,7 +68,10 @@ fn envelope(index: usize, raw: Value) -> Result<Envelope, AppError> {
Some("settlement") => EntityType::Settlement,
_ => return Err(bad("entity_type must be expense or settlement")),
};
let entity = raw.get("entity").cloned().unwrap_or(Value::Null);
let entity = raw
.get_mut("entity")
.map(Value::take)
.unwrap_or(Value::Null);
let entity_id = canonical_uuid(entity.get("id"))
.ok_or_else(|| bad("entity.id must be a lowercase hyphenated uuid"))?;
Ok(Envelope {
@@ -410,13 +413,13 @@ fn rejected(env: &Envelope, rejection: Rejection, current: Option<SyncEntity>) -
})
}
fn push_of(push_type: PushType, env: &Envelope, ctx: &Ctx<'_>) -> Option<PushMessage> {
Some(PushMessage {
fn push_of(push_type: PushType, env: &Envelope, ctx: &Ctx<'_>) -> PushMessage {
PushMessage {
push_type,
entity_id: Some(env.entity_id),
actor_user_id: ctx.caller.user_id,
count: 1,
})
}
}
async fn reload<K: Kind>(conn: &mut SqliteConnection, id: Uuid) -> Result<K::Wire, AppError> {
@@ -552,7 +555,7 @@ async fn process<K: Kind>(
.await?;
return Ok(Processed {
result: accepted(env, K::entity(after)),
push: push_of(K::DELETED, env, ctx),
push: Some(push_of(K::DELETED, env, ctx)),
});
}
// Created and deleted before it ever synced: store the tombstone, no audit, no push. It is validated like a
@@ -595,7 +598,7 @@ async fn process<K: Kind>(
.await?;
return Ok(Processed {
result: accepted(env, K::entity(after)),
push: push_of(K::CREATED, env, ctx),
push: Some(push_of(K::CREATED, env, ctx)),
});
};
@@ -638,7 +641,7 @@ async fn process<K: Kind>(
.await?;
Ok(Processed {
result: accepted(env, K::entity(after)),
push: push_of(K::UPDATED, env, ctx),
push: Some(push_of(K::UPDATED, env, ctx)),
})
}