diff --git a/crates/exact-api/src/compat/vector.rs b/crates/exact-api/src/compat/vector.rs index f6120f4..2b0394c 100644 --- a/crates/exact-api/src/compat/vector.rs +++ b/crates/exact-api/src/compat/vector.rs @@ -154,8 +154,16 @@ mod tests { assert!(validate(GLOBAL, 0, &mut json!({"frame": 3}))); assert!(validate(GLOBAL, 0, &mut json!({"frame": "3"}))); // the dummy box that EXACT's own check asks for is still accepted, with or without a frame - assert!(validate(GLOBAL, 0, &mut json!({"x1": 0, "y1": 0, "x2": 1, "y2": 1}))); - assert!(validate(GLOBAL, 0, &mut json!({"x1": 0, "y1": 0, "x2": 1, "y2": 1, "frame": 2}))); + assert!(validate( + GLOBAL, + 0, + &mut json!({"x1": 0, "y1": 0, "x2": 1, "y2": 1}) + )); + assert!(validate( + GLOBAL, + 0, + &mut json!({"x1": 0, "y1": 0, "x2": 1, "y2": 1, "frame": 2}) + )); // anything in between is not a vector of either kind assert!(!validate(GLOBAL, 0, &mut json!({"x1": 1, "y1": 2}))); assert!(!validate(GLOBAL, 0, &mut json!({"frame": 2, "z": 1}))); diff --git a/crates/exact-api/src/lib.rs b/crates/exact-api/src/lib.rs index 376e0e6..f237533 100644 --- a/crates/exact-api/src/lib.rs +++ b/crates/exact-api/src/lib.rs @@ -22,8 +22,8 @@ pub mod health; pub mod media; pub mod page; pub mod repair; -pub mod slides; pub mod scope; +pub mod slides; pub mod upload; pub mod v2; @@ -97,7 +97,10 @@ pub fn router(state: AppState) -> Router { // request bodies with files (bitmaps, media files) are larger than axum's default 2 MB .layer(axum::extract::DefaultBodyLimit::max(1 << 30)) // limited personal access tokens: refused before anything runs when they go beyond their scopes - .layer(axum::middleware::from_fn_with_state(state.clone(), scope::enforce)) + .layer(axum::middleware::from_fn_with_state( + state.clone(), + scope::enforce, + )) .with_state(state); // uploaded files (file fields); public like Django's `/media/` let r = r.nest_service("/media", tower_http::services::ServeDir::new(media_root)); diff --git a/crates/exact-api/src/scope.rs b/crates/exact-api/src/scope.rs index 54ba817..1beeee9 100644 --- a/crates/exact-api/src/scope.rs +++ b/crates/exact-api/src/scope.rs @@ -50,7 +50,9 @@ pub fn needed(method: &Method, path: &str) -> Option<&'static str> { | ["images", "api", ..] | ["images", "image", ..] => "images", // products and annotation types - ["api", "v2", "products", ..] | ["api", "v2", "annotation-types", ..] | ["administration", "api", "annotation_type", ..] => "catalog", + ["api", "v2", "products", ..] + | ["api", "v2", "annotation-types", ..] + | ["administration", "api", "annotation_type", ..] => "catalog", _ => return None, }) } @@ -75,7 +77,8 @@ pub async fn enforce(State(s): State, req: Request, next: Next) -> Res .and_then(|v| v.to_str().ok()) .and_then(|v| { let (kind, t) = v.split_once(' ')?; - kind.eq_ignore_ascii_case("bearer").then(|| t.trim().to_string()) + kind.eq_ignore_ascii_case("bearer") + .then(|| t.trim().to_string()) }); let Some(prefix) = token.as_deref().and_then(tokens::pat_prefix) else { return next.run(req).await; @@ -106,7 +109,11 @@ mod tests { use super::*; fn ok(scopes: &[&str], m: Method, p: &str) -> bool { - allows(&scopes.iter().map(|s| s.to_string()).collect::>(), &m, p) + allows( + &scopes.iter().map(|s| s.to_string()).collect::>(), + &m, + p, + ) } #[test] @@ -124,13 +131,26 @@ mod tests { assert!(ok(&j, Method::POST, "/api/v2/jobs/plugin/9/restart")); assert!(ok(&j, Method::DELETE, "/api/v2/jobs/plugin/9")); assert!(ok(&j, Method::POST, "/api/v2/registrations/manual")); - assert!(ok(&j, Method::POST, "/api/v1/images/images/5/register_images/")); + assert!(ok( + &j, + Method::POST, + "/api/v1/images/images/5/register_images/" + )); assert!(!ok(&j, Method::POST, "/api/v2/annotations")); assert!(!ok(&j, Method::PATCH, "/api/v2/images/5")); assert!(!ok(&j, Method::POST, "/api/v2/image-sets/3/images")); // worker routes, accounts, tokens and configuration are for nobody who is limited - for p in ["/api/v2/jobs/claim", "/api/v2/plugin-jobs/3/complete", "/api/v2/registration-jobs/3/fail", "/api/v2/plugins/register", - "/api/v2/users/3", "/api/v2/teams/1/members/4", "/api/v2/me/tokens", "/api/v2/me/preferences", "/api/v2/admin/users"] { + for p in [ + "/api/v2/jobs/claim", + "/api/v2/plugin-jobs/3/complete", + "/api/v2/registration-jobs/3/fail", + "/api/v2/plugins/register", + "/api/v2/users/3", + "/api/v2/teams/1/members/4", + "/api/v2/me/tokens", + "/api/v2/me/preferences", + "/api/v2/admin/users", + ] { assert!(!ok(&SCOPES, Method::POST, p), "{p}"); assert!(!ok(&SCOPES, Method::DELETE, p), "{p}"); } @@ -139,12 +159,21 @@ mod tests { #[test] fn catalog_covers_products_and_annotation_types_and_nothing_else() { let c = ["catalog"]; - for (m, p) in [(Method::POST, "/api/v2/products"), (Method::PATCH, "/api/v2/products/4"), (Method::DELETE, "/api/v2/products/4"), - (Method::POST, "/api/v2/products/4/annotation-types"), (Method::POST, "/api/v2/annotation-types"), - (Method::PATCH, "/api/v2/annotation-types/9"), (Method::DELETE, "/api/v2/annotation-types/9"), - (Method::POST, "/administration/api/annotation_type/create/")] { + for (m, p) in [ + (Method::POST, "/api/v2/products"), + (Method::PATCH, "/api/v2/products/4"), + (Method::DELETE, "/api/v2/products/4"), + (Method::POST, "/api/v2/products/4/annotation-types"), + (Method::POST, "/api/v2/annotation-types"), + (Method::PATCH, "/api/v2/annotation-types/9"), + (Method::DELETE, "/api/v2/annotation-types/9"), + (Method::POST, "/administration/api/annotation_type/create/"), + ] { assert!(ok(&c, m.clone(), p), "{m} {p}"); - assert!(!ok(&["annotate", "images", "jobs"], m.clone(), p), "{m} {p}"); + assert!( + !ok(&["annotate", "images", "jobs"], m.clone(), p), + "{m} {p}" + ); } assert!(!ok(&c, Method::POST, "/api/v2/annotations")); assert!(!ok(&c, Method::POST, "/api/v2/image-sets/3/images")); @@ -155,9 +184,21 @@ mod tests { fn annotate_and_images_are_separate() { assert!(ok(&["annotate"], Method::POST, "/api/v2/annotations")); assert!(ok(&["annotate"], Method::PATCH, "/api/v2/annotations/7")); - assert!(ok(&["annotate"], Method::POST, "/api/v1/annotations/annotations/")); - assert!(ok(&["annotate"], Method::POST, "/annotations/api/annotation/create/")); - assert!(!ok(&["annotate"], Method::POST, "/api/v2/image-sets/3/images")); + assert!(ok( + &["annotate"], + Method::POST, + "/api/v1/annotations/annotations/" + )); + assert!(ok( + &["annotate"], + Method::POST, + "/annotations/api/annotation/create/" + )); + assert!(!ok( + &["annotate"], + Method::POST, + "/api/v2/image-sets/3/images" + )); assert!(ok(&["images"], Method::POST, "/api/v2/image-sets/3/images")); assert!(ok(&["images"], Method::POST, "/images/image/upload/3/")); assert!(ok(&["images"], Method::DELETE, "/api/v2/images/5")); diff --git a/crates/exact-api/src/slides.rs b/crates/exact-api/src/slides.rs index f1ef727..1ce9988 100644 --- a/crates/exact-api/src/slides.rs +++ b/crates/exact-api/src/slides.rs @@ -531,12 +531,13 @@ async fn centered_snapshot( )) } }; - let default_frame: i32 = sqlx::query_scalar("SELECT \"defaultFrame\" FROM images_image WHERE id = $1") - .bind(img.id) - .fetch_optional(&s.pool) - .await - .map_err(db_err)? - .unwrap_or(0); + let default_frame: i32 = + sqlx::query_scalar("SELECT \"defaultFrame\" FROM images_image WHERE id = $1") + .bind(img.id) + .fetch_optional(&s.pool) + .await + .map_err(db_err)? + .unwrap_or(0); let path = img.path(&s, 1, 1).to_string_lossy().into_owned(); let st = s.slides.clone(); // the corner: Django's int(cx - w / 2) @@ -545,7 +546,8 @@ async fn centered_snapshot( let slide = st.slides.get(&path)?; let (sw, sh) = slide.level_dimensions().first().copied().unwrap_or((0, 0)); let (sw, sh) = (sw as i64, sh as i64); - let mut canvas = image::RgbImage::from_pixel(w as u32, h as u32, image::Rgb([255, 255, 255])); + let mut canvas = + image::RgbImage::from_pixel(w as u32, h as u32, image::Rgb([255, 255, 255])); // the part of the wanted region that lies inside the slide let (ix0, iy0) = (x0.max(0), y0.max(0)); let (ix1, iy1) = ((x0 + w).min(sw), (y0 + h).min(sh)); @@ -555,7 +557,8 @@ async fn centered_snapshot( } else { 0 }; - let part = slide.read_region(ix0, iy0, 0, (ix1 - ix0) as u32, (iy1 - iy0) as u32, frame)?; + let part = + slide.read_region(ix0, iy0, 0, (ix1 - ix0) as u32, (iy1 - iy0) as u32, frame)?; for (px, py, c) in part.enumerate_pixels() { // transparent pixels (a slide with no data there) are white, too let a = c[3] as u32; diff --git a/crates/exact-api/src/v2/access_tokens.rs b/crates/exact-api/src/v2/access_tokens.rs index 46ddc61..c789d7c 100644 --- a/crates/exact-api/src/v2/access_tokens.rs +++ b/crates/exact-api/src/v2/access_tokens.rs @@ -15,6 +15,7 @@ //! A token cannot make tokens: managing them needs the password or a sign-in session, and not an impersonation (an administrator who //! impersonates somebody must not be able to mint a lasting credential in their name). +use crate::scope::SCOPES; use crate::{ auth::{authenticate_account, require_user, AuthKind, Principal}, compat::engine::db_err, @@ -29,7 +30,6 @@ use axum::{ }; use chrono::{DateTime, Duration, Utc}; use exact_auth::tokens::{generate_pat, hash_token}; -use crate::scope::SCOPES; use exact_db::users; use serde::Deserialize; use serde_json::{json, Value}; @@ -90,14 +90,15 @@ async fn json_of(s: &AppState, rows: Vec, with_user: bool) -> ApiResult> = - sqlx::query_as::<_, (i64, Vec)>("SELECT token_id, scopes FROM exact_rust_token_scope WHERE token_id = ANY($1)") - .bind(&ids) - .fetch_all(&s.pool) - .await - .map_err(db_err)? - .into_iter() - .collect(); + let scopes: HashMap> = sqlx::query_as::<_, (i64, Vec)>( + "SELECT token_id, scopes FROM exact_rust_token_scope WHERE token_id = ANY($1)", + ) + .bind(&ids) + .fetch_all(&s.pool) + .await + .map_err(db_err)? + .into_iter() + .collect(); let now = Utc::now(); Ok(rows .into_iter() @@ -181,7 +182,9 @@ async fn create( let scopes = match b.scopes { None => None, Some(_) if b.read_only => { - return Err(bad("A read-only token cannot have scopes: it may only look.")) + return Err(bad( + "A read-only token cannot have scopes: it may only look.", + )) } Some(mut v) => { v.sort(); @@ -205,7 +208,9 @@ async fn create( .await .map_err(db_err)?; if mine.len() != teams.len() { - return Err(bad("A token can only be restricted to teams you belong to.")); + return Err(bad( + "A token can only be restricted to teams you belong to.", + )); } } let (token, prefix) = generate_pat(); @@ -266,11 +271,13 @@ async fn revoke(s: &AppState, id: i64, owner: Option) -> ApiResult = vec_value.get("frame").and_then(Value::as_i64).map(|f| f.to_string()); + let frame: Option = vec_value + .get("frame") + .and_then(Value::as_i64) + .map(|f| f.to_string()); let existing: Option<(i64, bool)> = if atype.vector_type == vector::GLOBAL { let competitive = sqlx::query_scalar::<_, i32>( "SELECT collaboration_type FROM images_imageset WHERE id = $1", diff --git a/crates/exact-api/src/v2/catalog.rs b/crates/exact-api/src/v2/catalog.rs index 6a548ea..f350547 100644 --- a/crates/exact-api/src/v2/catalog.rs +++ b/crates/exact-api/src/v2/catalog.rs @@ -553,8 +553,15 @@ fn type_fields(d: &Map) -> ApiResult { None => None, Some(Value::Null) => Some(None), Some(Value::String(t)) if t.trim().is_empty() => Some(None), - Some(Value::String(t)) if t.trim().chars().count() <= 50 => Some(Some(t.trim().to_string())), - Some(_) => return Err(field_err("seg_group", "A group name of up to 50 characters, or empty for none.")), + Some(Value::String(t)) if t.trim().chars().count() <= 50 => { + Some(Some(t.trim().to_string())) + } + Some(_) => { + return Err(field_err( + "seg_group", + "A group name of up to 50 characters, or empty for none.", + )) + } }; let w = float(d.get("default_width")) .map_err(|_| field_err("default_width", "A number is required."))?; @@ -722,7 +729,11 @@ async fn usage_report(s: &AppState, id: i64) -> ApiResult { ("plugin results", "SELECT i.id, i.name, i.image_set_id FROM processing_pluginresultannotation a JOIN images_image i ON i.id = a.image_id WHERE a.annotation_type_id = $1"), ]; for (what, sql) in kinds { - let rows: Vec<(i64, String, i64)> = sqlx::query_as(sql).bind(id).fetch_all(&s.pool).await.map_err(db_err)?; + let rows: Vec<(i64, String, i64)> = sqlx::query_as(sql) + .bind(id) + .fetch_all(&s.pool) + .await + .map_err(db_err)?; if rows.is_empty() { continue; } @@ -738,8 +749,16 @@ async fn usage_report(s: &AppState, id: i64) -> ApiResult { .take(8) .map(|((iid, name, set), n)| format!("{name} (image {iid}, image set {set}): {n}")) .collect(); - let more = if per.len() > 8 { format!(", and {} more images", per.len() - 8) } else { String::new() }; - parts.push(format!("{} {what} in {}{more}", rows.len(), shown.join("; "))); + let more = if per.len() > 8 { + format!(", and {} more images", per.len() - 8) + } else { + String::new() + }; + parts.push(format!( + "{} {what} in {}{more}", + rows.len(), + shown.join("; ") + )); } Ok(parts.join(". ")) } @@ -759,11 +778,12 @@ pub async fn type_usage_h( "annotationtype", ) .await?; - let name: Option = sqlx::query_scalar("SELECT name FROM annotations_annotationtype WHERE id = $1") - .bind(id) - .fetch_optional(&s.pool) - .await - .map_err(db_err)?; + let name: Option = + sqlx::query_scalar("SELECT name FROM annotations_annotationtype WHERE id = $1") + .bind(id) + .fetch_optional(&s.pool) + .await + .map_err(db_err)?; let Some(name) = name else { return Err(ApiError::not_found("Not found.")); }; @@ -789,7 +809,12 @@ pub async fn type_usage_h( results += x; let image: i64 = r.get(0); if let Some(last) = places.last_mut().filter(|p| p["image"] == json!(image)) { - for (k, n) in [("annotations", l), ("deleted", g), ("versions", v), ("results", x)] { + for (k, n) in [ + ("annotations", l), + ("deleted", g), + ("versions", v), + ("results", x), + ] { last[k] = json!(last[k].as_i64().unwrap_or(0) + n); } continue; @@ -987,11 +1012,12 @@ pub async fn type_patch_h( } set_group(&s, id, &f.seg_group).await?; // the vector type of a type in use cannot change: annotations hold vectors of that shape - let current_shape: Option = sqlx::query_scalar("SELECT vector_type FROM annotations_annotationtype WHERE id = $1") - .bind(id) - .fetch_optional(&s.pool) - .await - .map_err(db_err)?; + let current_shape: Option = + sqlx::query_scalar("SELECT vector_type FROM annotations_annotationtype WHERE id = $1") + .bind(id) + .fetch_optional(&s.pool) + .await + .map_err(db_err)?; if f.vector_type.is_some() && f.vector_type == current_shape { // the same shape again (the administration screen sends the whole type): nothing to change, also when annotations use it } else if f.vector_type.is_some() && type_usage(&s, id).await? == 0 { @@ -1036,7 +1062,9 @@ pub async fn type_delete_h( } // `?purge_deleted=true`: the annotations that were deleted (and can still be restored) go for good with the type, and with them what // hangs on them (versions of image sets). Live annotations and plugin results still stop the deletion. - let purge = q.get("purge_deleted").is_some_and(|v| v == "true" || v == "1"); + let purge = q + .get("purge_deleted") + .is_some_and(|v| v == "true" || v == "1"); let used = type_usage(&s, id).await?; if used > 0 { let blockers: i64 = sqlx::query_scalar( @@ -1055,16 +1083,22 @@ pub async fn type_delete_h( format!( "The annotation type is used by {used} annotations, versions or results. {}.{}", usage_report(&s, id).await?, - if blockers == 0 { " Delete with the deleted annotations to remove them for good." } else { "" } + if blockers == 0 { + " Delete with the deleted annotations to remove them for good." + } else { + "" + } ), )); } let mut tx = s.pool.begin().await.map_err(db_err)?; - let gone: Vec = sqlx::query_scalar("SELECT id FROM annotations_annotation WHERE annotation_type_id = $1 AND deleted") - .bind(id) - .fetch_all(&mut *tx) - .await - .map_err(db_err)?; + let gone: Vec = sqlx::query_scalar( + "SELECT id FROM annotations_annotation WHERE annotation_type_id = $1 AND deleted", + ) + .bind(id) + .fetch_all(&mut *tx) + .await + .map_err(db_err)?; cascade::delete_rows(&mut tx, "annotations_annotation", &gone).await?; cascade::delete_rows(&mut tx, "annotations_annotationtype", &[id]).await?; tx.commit().await.map_err(db_err)?; diff --git a/crates/exact-api/src/v2/jobs.rs b/crates/exact-api/src/v2/jobs.rs index 70c07b8..3237602 100644 --- a/crates/exact-api/src/v2/jobs.rs +++ b/crates/exact-api/src/v2/jobs.rs @@ -80,7 +80,9 @@ pub(crate) const CONNECTED_SQL: &str = "GREATEST((SELECT ps.seen_at FROM exact_r (SELECT max(cq.updated_time) FROM processing_pluginjob cq WHERE cq.plugin_id = pl.id AND cq.attached_worker IS NOT NULL AND cq.attached_worker <> '')) \ > now() - interval '7 days'"; -static TOUCHED: std::sync::OnceLock>> = std::sync::OnceLock::new(); +static TOUCHED: std::sync::OnceLock< + std::sync::Mutex>, +> = std::sync::OnceLock::new(); /// Records that a worker is serving these plugins now (at most one write a minute per plugin). pub(crate) async fn touch_plugins(pool: &sqlx::PgPool, ids: &[i64]) { @@ -263,7 +265,12 @@ async fn heartbeat_h( let kinds: Vec<&str> = d .get("kinds") .and_then(Value::as_array) - .map(|a| a.iter().filter_map(Value::as_str).filter(|k| KINDS.contains(k)).collect()) + .map(|a| { + a.iter() + .filter_map(Value::as_str) + .filter(|k| KINDS.contains(k)) + .collect() + }) .unwrap_or_default(); let plugins: Vec = d .get("plugins") diff --git a/crates/exact-api/src/v2/mod.rs b/crates/exact-api/src/v2/mod.rs index c3996ac..c2edb59 100644 --- a/crates/exact-api/src/v2/mod.rs +++ b/crates/exact-api/src/v2/mod.rs @@ -1,6 +1,7 @@ //! `/api/v2`: the clean API. Phase 2 provides session authentication for the new UI; //! resources follow in Phase 3. +pub mod access_tokens; pub mod account; pub mod admin; pub mod admin_log; @@ -17,7 +18,6 @@ pub mod jobs; pub mod linked; pub mod move_image; pub mod passkeys; -pub mod access_tokens; pub mod plugins; pub mod preferences; pub mod processing; diff --git a/crates/exact-api/src/v2/resources.rs b/crates/exact-api/src/v2/resources.rs index 9287a49..885a3bc 100644 --- a/crates/exact-api/src/v2/resources.rs +++ b/crates/exact-api/src/v2/resources.rs @@ -88,7 +88,10 @@ pub fn routes() -> Router { .patch(catalog::type_patch_h) .delete(catalog::type_delete_h), ) - .route("/api/v2/annotation-types/{id}/usage", get(catalog::type_usage_h)) + .route( + "/api/v2/annotation-types/{id}/usage", + get(catalog::type_usage_h), + ) .route( "/api/v2/products", get(products_list).post(catalog::product_create_h), diff --git a/crates/exact-api/src/v2/seg3d.rs b/crates/exact-api/src/v2/seg3d.rs index 879f932..18d1024 100644 --- a/crates/exact-api/src/v2/seg3d.rs +++ b/crates/exact-api/src/v2/seg3d.rs @@ -96,7 +96,11 @@ async fn group_lock( ) -> ApiResult<(Vec, Option>)> { static GROUPS: tokio::sync::Mutex<()> = tokio::sync::Mutex::const_new(()); let mates = group_mates(s, annotation).await?; - let guard = if mates.is_empty() { None } else { Some(GROUPS.lock().await) }; + let guard = if mates.is_empty() { + None + } else { + Some(GROUPS.lock().await) + }; Ok((mates, guard)) } @@ -136,7 +140,12 @@ async fn touch_mate( let open = load_entry(s, mate, &Target { image }).await?; let mut e = open.lock().await; let cur = e.vol.tile(key).cloned(); - let mut next = cur.clone().unwrap_or_else(|| vec![0u8; T * T].into_boxed_slice().try_into().expect("tile")); + let mut next = cur.clone().unwrap_or_else(|| { + vec![0u8; T * T] + .into_boxed_slice() + .try_into() + .expect("tile") + }); let mut moved = vec![0u8; T * T]; let mut any = false; for i in 0..T * T { @@ -748,7 +757,11 @@ async fn commit( let want_bits = !mates.is_empty(); let (before, after, bits) = tokio::task::spawn_blocking(move || { let before_tiles = j.into_before(); - let bits = if want_bits { gained(&before_tiles, &settled) } else { Vec::new() }; + let bits = if want_bits { + gained(&before_tiles, &settled) + } else { + Vec::new() + }; let before: Vec<(Key, Option>)> = before_tiles .into_iter() .map(|(k, t)| (k, t.map(|t| png_of(&t)))) @@ -779,7 +792,11 @@ async fn commit( let mut others: Vec = linked.iter().map(|l| l.0).collect(); others.dedup(); if changed { - guard.undo.push(Step { before, after, linked }); + guard.undo.push(Step { + before, + after, + linked, + }); if guard.undo.len() > MAX_UNDO { guard.undo.remove(0); } @@ -871,7 +888,10 @@ async fn step_h(s: AppState, headers: HeaderMap, annotation: i64, dir: Dir) -> A // the voxels the step took from the other masks of the group: back on undo, taken again on redo let mut others: Vec = Vec::new(); for (mate, key, bits) in &step.linked { - if touch_mate(&s, *mate, t.image, *key, bits, matches!(dir, Dir::Redo)).await?.is_some() { + if touch_mate(&s, *mate, t.image, *key, bits, matches!(dir, Dir::Redo)) + .await? + .is_some() + { others.push(*mate); } } diff --git a/crates/exact-cli/src/main.rs b/crates/exact-cli/src/main.rs index 406968d..5410469 100644 --- a/crates/exact-cli/src/main.rs +++ b/crates/exact-cli/src/main.rs @@ -128,8 +128,16 @@ async fn main() -> anyhow::Result<()> { match exact_wsi::formats::SlideCache::new(1).get(&path) { Ok(slide) => { println!("opened: {path}"); - println!("level 0: {:?} levels: {}", slide.level_dimensions().first(), slide.level_dimensions().len()); - println!("frames: {} ({})", slide.frame_count(), slide.frame_kind().as_str()); + println!( + "level 0: {:?} levels: {}", + slide.level_dimensions().first(), + slide.level_dimensions().len() + ); + println!( + "frames: {} ({})", + slide.frame_count(), + slide.frame_kind().as_str() + ); for plane in 0..3 { if let Some(d) = slide.plane_dimensions(plane) { println!("plane {plane}: {d:?}, {} slices", slide.plane_frames(plane)); diff --git a/crates/exact-wsi/src/crop.rs b/crates/exact-wsi/src/crop.rs index 907cf51..c8486f4 100644 --- a/crates/exact-wsi/src/crop.rs +++ b/crates/exact-wsi/src/crop.rs @@ -208,7 +208,11 @@ mod tests { band.put_pixel(1, 0, image::Rgba([0, 0, 0, 128])); // half transparent black let t = rgb_tile(&band, 0, 4); assert_eq!(&t[0..3], &[255, 255, 255]); - assert!(t[3..6].iter().all(|&v| (126..=129).contains(&v)), "{:?}", &t[3..6]); + assert!( + t[3..6].iter().all(|&v| (126..=129).contains(&v)), + "{:?}", + &t[3..6] + ); assert_eq!(&t[6..9], &[10, 20, 30]); // outside the band (rows 4.. and the columns past 300) is white let t2 = rgb_tile(&band, 256, 4); diff --git a/crates/exact-wsi/src/nifti.rs b/crates/exact-wsi/src/nifti.rs index a75ac3b..d577ed0 100644 --- a/crates/exact-wsi/src/nifti.rs +++ b/crates/exact-wsi/src/nifti.rs @@ -810,7 +810,9 @@ mod tests { assert_eq!(a.render(p, 1).as_raw(), b.render(p, 1).as_raw()); } // the second open of the gz finds the inflated sidecar - assert!(sidecar_in(&cache_dir(), gz.to_str().unwrap()).unwrap().exists()); + assert!(sidecar_in(&cache_dir(), gz.to_str().unwrap()) + .unwrap() + .exists()); assert!(Nifti::open(gz.to_str().unwrap()).is_ok()); std::fs::remove_dir_all(&dir).ok(); } diff --git a/crates/exact-wsi/src/repair.rs b/crates/exact-wsi/src/repair.rs index c2972e5..20e38b5 100644 --- a/crates/exact-wsi/src/repair.rs +++ b/crates/exact-wsi/src/repair.rs @@ -42,7 +42,7 @@ pub(crate) fn reduce(src: &RgbaImage, samples: usize) -> Vec { let o = ((oy as u64 * TILE + ox as u64) as usize) * samples; if let Some(div) = std::num::NonZeroU32::new(n) { for c in 0..3 { - out[o + c] = ((sum[c] + n / 2) / div.get()) as u8; + out[o + c] = ((sum[c] + n / 2) / div) as u8; } } if samples == 4 {