diff options
| author | Alexander_Kabui <alexanderkabua@gmail.com> | 2026-10-04 08:42:02 +0300 |
|---|---|---|
| committer | Alexander_Kabui <alexanderkabua@gmail.com> | 2026-10-04 08:51:12 +0300 |
| commit | 924bcf3d25c01ccfd1cdf04bcc0308c5c1fd4ddb (patch) | |
| tree | 2e7ee5676a6e38570771cd7bb889606f9ddde401 /src | |
| parent | 4a2cf5b8cbc95bd973e5e2fc8a331ca98f116df0 (diff) | |
| download | genenetwork4-924bcf3d25c01ccfd1cdf04bcc0308c5c1fd4ddb.tar.gz | |
Format all Rust sources with cargo fmt (no behavior change)
Line-wrapping and canonical import ordering only (verified with git diff -w). Establishes rustfmt's output as the canonical style before the search/correlation work lands.
Diffstat (limited to 'src')
| -rw-r--r-- | src/config.rs | 5 | ||||
| -rw-r--r-- | src/db.rs | 53 | ||||
| -rw-r--r-- | src/error.rs | 10 | ||||
| -rw-r--r-- | src/lib.rs | 4 | ||||
| -rw-r--r-- | src/response.rs | 10 | ||||
| -rw-r--r-- | src/routes/correlation.rs | 12 | ||||
| -rw-r--r-- | src/routes/groups.rs | 6 | ||||
| -rw-r--r-- | src/routes/species.rs | 6 |
8 files changed, 80 insertions, 26 deletions
diff --git a/src/config.rs b/src/config.rs index 496ff39..75adaf2 100644 --- a/src/config.rs +++ b/src/config.rs @@ -27,7 +27,10 @@ impl Config { let mut values = HashMap::<String, String>::new(); // Layer 1: built-in defaults. - values.insert("SQL_URI".to_string(), "mysql://webqtlout:webqtlout@127.0.0.1/db_webqtl".to_string()); + values.insert( + "SQL_URI".to_string(), + "mysql://webqtlout:webqtlout@127.0.0.1/db_webqtl".to_string(), + ); values.insert("GENENETWORK4_PORT".to_string(), "3000".to_string()); // Layers 2 and 3: config files, in increasing priority. diff --git a/src/db.rs b/src/db.rs index 462639e..7ada339 100644 --- a/src/db.rs +++ b/src/db.rs @@ -1,7 +1,7 @@ //! Read-only access to the GeneNetwork MariaDB database (db_webqtl). use mysql::prelude::{FromRow, Queryable}; -use mysql::{params, Opts, Pool}; +use mysql::{Opts, Pool, params}; use serde::Serialize; /// Connection string, mysql://user:password@host/database. Same @@ -62,10 +62,21 @@ pub fn get_species_by_name(name: &str) -> Result<Option<SpeciesDetail>, mysql::E OR SpeciesName = :name", mysql::params! { "name" => name }, ) - .map(|row: Option<(u16, Option<i32>, Option<String>, String, Option<String>, String, Option<String>, Option<i16>, Option<i32>, Option<i16>)>| { - row.map( - |(id, species_id, species_name, name, menu_name, full_name, family, family_order_id, taxonomy_id, order_id)| { - SpeciesDetail { + .map( + |row: Option<( + u16, + Option<i32>, + Option<String>, + String, + Option<String>, + String, + Option<String>, + Option<i16>, + Option<i32>, + Option<i16>, + )>| { + row.map( + |( id, species_id, species_name, @@ -76,10 +87,23 @@ pub fn get_species_by_name(name: &str) -> Result<Option<SpeciesDetail>, mysql::E family_order_id, taxonomy_id, order_id, - } - }, - ) - }) + )| { + SpeciesDetail { + id, + species_id, + species_name, + name, + menu_name, + full_name, + family, + family_order_id, + taxonomy_id, + order_id, + } + }, + ) + }, + ) } /// Summary of one InbredSet row, matching the shape of GeneNetwork2's @@ -106,7 +130,16 @@ pub fn get_all_groups() -> Result<Vec<Group>, mysql::Error> { "SELECT InbredSetId, SpeciesId, InbredSetName, Name, FullName, \ public, MappingMethodId, GeneticType \ FROM InbredSet ORDER BY Name ASC", - |(id, species_id, display_name, name, full_name, public, mapping_method_id, genetic_type)| { + |( + id, + species_id, + display_name, + name, + full_name, + public, + mapping_method_id, + genetic_type, + )| { Group { id, species_id, diff --git a/src/error.rs b/src/error.rs index bbc5413..49e1574 100644 --- a/src/error.rs +++ b/src/error.rs @@ -9,9 +9,9 @@ //! service has no fixed public domain; RFC 7807 explicitly allows `type` //! to be a relative URI reference. +use axum::Json; use axum::http::StatusCode; use axum::response::{IntoResponse, Response}; -use axum::Json; use serde::Serialize; #[derive(Serialize, utoipa::ToSchema)] @@ -28,7 +28,13 @@ pub struct ApiError { } impl ApiError { - pub fn new(status: StatusCode, code: &str, title: &str, detail: String, operation_id: &str) -> Self { + pub fn new( + status: StatusCode, + code: &str, + title: &str, + detail: String, + operation_id: &str, + ) -> Self { ApiError { r#type: format!("/errors/{code}"), title: title.to_string(), diff --git a/src/lib.rs b/src/lib.rs index 620aeb6..ccdafd8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,8 @@ use axum::Json; use axum::Router; -use tower_http::request_id::{MakeRequestUuid, PropagateRequestIdLayer, RequestId, SetRequestIdLayer}; +use tower_http::request_id::{ + MakeRequestUuid, PropagateRequestIdLayer, RequestId, SetRequestIdLayer, +}; use utoipa::OpenApi; use utoipa_axum::router::OpenApiRouter; use utoipa_axum::routes; diff --git a/src/response.rs b/src/response.rs index 55dea57..d795f30 100644 --- a/src/response.rs +++ b/src/response.rs @@ -28,7 +28,10 @@ pub struct NextAction { impl<T: Serialize> Envelope<T> { pub fn of(data: T) -> Self { - Envelope { data, next: Vec::new() } + Envelope { + data, + next: Vec::new(), + } } pub fn with_next(mut self, href: &str, description: &str) -> Self { @@ -49,10 +52,7 @@ mod tests { let envelope = Envelope::of(vec!["mouse", "rat"]) .with_next("/species/mouse", "Drill down into one species"); let json = serde_json::to_value(&envelope).unwrap(); - assert_eq!( - json["data"], - serde_json::json!(["mouse", "rat"]) - ); + assert_eq!(json["data"], serde_json::json!(["mouse", "rat"])); assert_eq!(json["next"][0]["href"], "/species/mouse"); assert_eq!( json["next"][0]["description"], diff --git a/src/routes/correlation.rs b/src/routes/correlation.rs index d99190d..3a74e15 100644 --- a/src/routes/correlation.rs +++ b/src/routes/correlation.rs @@ -5,8 +5,8 @@ //! integration is specified in topics/gn4/gn4-correlation.gmi //! (gn-gemtext-threads): correlation_rust in-process, rev-pinned. -use axum::extract::Extension; use axum::Json; +use axum::extract::Extension; use serde::{Deserialize, Serialize}; use tower_http::request_id::RequestId; @@ -49,8 +49,14 @@ pub async fn correlation( let _ = (request_id_string(&request_id), &request.method); Ok(Json( Envelope::of(vec![ - CorrelationHit { trait_id: 1_435_863, correlation: 0.91 }, - CorrelationHit { trait_id: 1_435_987, correlation: 0.87 }, + CorrelationHit { + trait_id: 1_435_863, + correlation: 0.91, + }, + CorrelationHit { + trait_id: 1_435_987, + correlation: 0.87, + }, ]) .with_next("/api/v2/correlation", "Correlate another trait") .with_next("/species", "Narrow by species"), diff --git a/src/routes/groups.rs b/src/routes/groups.rs index dd8c232..7c32ae9 100644 --- a/src/routes/groups.rs +++ b/src/routes/groups.rs @@ -1,9 +1,9 @@ //! Groups (InbredSet) domain endpoints: read-only access to the //! InbredSet table and its strains. +use axum::Json; use axum::extract::{Extension, Path, Query}; use axum::http::StatusCode; -use axum::Json; use tower_http::request_id::RequestId; use crate::db; @@ -14,7 +14,9 @@ use crate::request_id_string; (status = 200, description = "All groups (InbredSet rows) in the database", body = Vec<db::Group>), (status = 500, description = "Database error", body = ApiError) ))] -pub async fn groups(Extension(request_id): Extension<RequestId>) -> Result<Json<Vec<db::Group>>, ApiError> { +pub async fn groups( + Extension(request_id): Extension<RequestId>, +) -> Result<Json<Vec<db::Group>>, ApiError> { let rid = request_id_string(&request_id); tokio::task::spawn_blocking(db::get_all_groups) .await diff --git a/src/routes/species.rs b/src/routes/species.rs index c7c1b54..ef775f4 100644 --- a/src/routes/species.rs +++ b/src/routes/species.rs @@ -1,8 +1,8 @@ //! Species domain endpoints: read-only access to the Species table. +use axum::Json; use axum::extract::{Extension, Path}; use axum::http::StatusCode; -use axum::Json; use tower_http::request_id::RequestId; use crate::db; @@ -13,7 +13,9 @@ use crate::request_id_string; (status = 200, description = "All species in the database", body = Vec<db::Species>), (status = 500, description = "Database error", body = ApiError) ))] -pub async fn species(Extension(request_id): Extension<RequestId>) -> Result<Json<Vec<db::Species>>, ApiError> { +pub async fn species( + Extension(request_id): Extension<RequestId>, +) -> Result<Json<Vec<db::Species>>, ApiError> { let rid = request_id_string(&request_id); // mysql's Conn is blocking; run it on a blocking thread so it doesn't // stall the async runtime. |
