Skip to content

PhotoCraft: An open-source, photo editor written by scratch in pure Rust

Tile grid overlay: gate rayon to native so the web build compiles (#4694)

Brandon Thomas72b499a28ff8
diff --git a/crates/ui-egui/src/tile_overlay.rs b/crates/ui-egui/src/tile_overlay.rs
index 03d8156dd..731ddc06b 100644
--- a/crates/ui-egui/src/tile_overlay.rs
+++ b/crates/ui-egui/src/tile_overlay.rs
@@ -21,6 +21,7 @@ use std::sync::Arc;
use egui::{Align2, Color32, FontId, Painter, Shape, Stroke};
use photocraft_geom::{Rect as DRect, TILE_SIZE, TileCoord};
use photocraft_raster::{Surface, Tile};
+#[cfg(not(target_arch = "wasm32"))]
use rayon::prelude::*;
use crate::PhotocraftApp;
@@ -70,11 +71,18 @@ pub fn tile_infos(s: &Surface, parallel: bool) -> Vec<TileInfo> {
by_ptr.entry(ptr(t)).or_insert(t);
}
let distinct: Vec<(usize, &Arc<Tile>)> = by_ptr.into_iter().collect();
+ // rayon is a native-only dependency; the web build hashes serially.
+ #[cfg(not(target_arch = "wasm32"))]
let hashed: Vec<(usize, u64)> = if parallel {
distinct.par_iter().map(|(p, t)| (*p, content_hash(t))).collect()
} else {
distinct.iter().map(|(p, t)| (*p, content_hash(t))).collect()
};
+ #[cfg(target_arch = "wasm32")]
+ let hashed: Vec<(usize, u64)> = {
+ let _ = parallel;
+ distinct.iter().map(|(p, t)| (*p, content_hash(t))).collect()
+ };
let hash_of: HashMap<usize, u64> = hashed.into_iter().collect();
let mut count: HashMap<u64, usize> = HashMap::new();
for (_, t) in s.tiles() {