chore(highscores): align dependency and lint standards
Build TDK Pinball / build (macos-latest) (push) Canceled after 0s
Build TDK Pinball / build (ubuntu-latest) (push) Canceled after 0s
Build TDK Pinball / build (windows-latest) (push) Canceled after 0s

Update the high-score service to the latest compatible direct releases while
keeping the requested Cargo.toml ranges: 0.x crates use their latest minor
line and 1.x crates use their major-only range. Refresh the standalone lockfile
so it resolves axum 0.8.9, rusqlite 0.40.2, serde 1.0.229, serde_json 1.0.151,
Tokio 1.53.1, and the latest dev-tool releases.

Copy the main package's Clippy policy and make the repository's formatting
recipes cover the service. The nested crate inherits the parent rustfmt.toml,
so one configuration remains authoritative; newly required documentation and
borrow style also keep the stricter pedantic policy clean.

Test Plan:
- `cargo update --manifest-path highscore-server/Cargo.toml` -- passed
- `just test` -- passed (3 service tests and 137 game tests)
- `just clippy` -- passed with the shared lint policy
- `just fmt-highscore-server` and `cargo +nightly fmt --manifest-path highscore-server/Cargo.toml -- --check` -- passed
- `cargo tree --manifest-path highscore-server/Cargo.toml --depth 1` -- confirmed latest direct resolutions
- `rustfmt +nightly --print-config current` -- confirmed the parent rustfmt settings
- `rumdl check --flavor commonmark highscore-server/README.md` -- passed
- `git diff --cached --check` -- passed
This commit is contained in:
2026-08-29 16:03:11 +02:00
parent 3b7b84affe
commit a81741b470
6 changed files with 184 additions and 20 deletions
+23 -2
View File
@@ -39,10 +39,21 @@ impl From<rusqlite::Error> for StoreError {
pub struct HighScoreStore(Arc<Mutex<Connection>>);
impl HighScoreStore {
/// Open or create a SQLite-backed high-score store.
///
/// # Errors
///
/// Returns the SQLite error raised while opening or initializing the
/// database.
pub fn open(path: impl AsRef<Path>) -> Result<Self, rusqlite::Error> {
Self::from_connection(Connection::open(path)?)
}
/// Create an in-memory high-score store for tests or short-lived runs.
///
/// # Errors
///
/// Returns the SQLite error raised while initializing the database.
pub fn open_in_memory() -> Result<Self, rusqlite::Error> {
Self::from_connection(Connection::open_in_memory()?)
}
@@ -60,6 +71,11 @@ impl HighScoreStore {
Ok(Self(Arc::new(Mutex::new(connection))))
}
/// Return the current table in descending score order.
///
/// # Errors
///
/// Returns an error if the database lock or query fails.
pub fn list(&self) -> Result<Vec<HighScore>, StoreError> {
let connection = self.0.lock().map_err(|_| StoreError::Poisoned)?;
let mut statement = connection.prepare(
@@ -83,6 +99,11 @@ impl HighScoreStore {
Ok(scores)
}
/// Add one score and return the resulting canonical top ten.
///
/// # Errors
///
/// Returns an error if the database lock or transaction fails.
pub fn submit(&self, entry: &HighScore) -> Result<Vec<HighScore>, StoreError> {
{
let mut connection = self.0.lock().map_err(|_| StoreError::Poisoned)?;
@@ -125,7 +146,7 @@ fn invalid_request(message: &'static str) -> Response {
.into_response()
}
fn validate_request(request: SubmitRequest) -> Result<HighScore, &'static str> {
fn validate_request(request: &SubmitRequest) -> Result<HighScore, &'static str> {
let name = request.name.trim();
if name.is_empty() {
return Err("name must not be empty");
@@ -157,7 +178,7 @@ async fn submit_high_score(
State(store): State<HighScoreStore>,
Json(request): Json<SubmitRequest>,
) -> Response {
let entry = match validate_request(request) {
let entry = match validate_request(&request) {
Ok(entry) => entry,
Err(message) => return invalid_request(message),
};