Skip to content

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

style: apply missing cargo fmt formatting

David Bonnierd5d709f701e4
diff --git a/apps/photocraft/src/services.rs b/apps/photocraft/src/services.rs
index 1b26a3bcd..9a1a6c138 100644
--- a/apps/photocraft/src/services.rs
+++ b/apps/photocraft/src/services.rs
@@ -551,9 +551,7 @@ pub fn native(automation: Option<photocraft_automation::AuthorizedWorkspace>) ->
})),
save_file: Some(Arc::new(save_file)),
recovery_save_file: Some(Arc::new(recovery_save_file)),
- recovery_write: Some(Box::new(|path: &str, bytes: &[u8]| {
- photocraft_io::write_recovery_copy_bytes(Path::new(path), bytes).map_err(|e| e.to_string())
- })),
+ recovery_write: Some(Box::new(|path: &str, bytes: &[u8]| photocraft_io::write_recovery_copy_bytes(Path::new(path), bytes).map_err(|e| e.to_string()))),
file_dialog: Some(Box::new(show_file_dialog)),
write: Some(Box::new(|path: &str, bytes: &[u8]| write_atomic(Path::new(path), bytes))),
file_stamp: Some(Box::new(|path: &str| {
diff --git a/crates/io/src/recovery.rs b/crates/io/src/recovery.rs
index 214ae6e10..bc3c5c55e 100644
--- a/crates/io/src/recovery.rs
+++ b/crates/io/src/recovery.rs
@@ -4,15 +4,17 @@
//!
//! There is deliberately no fallback to `rename`, which can replace files.
-use std::path::Path;
use crate::IoError;
+use std::path::Path;
#[cfg(not(target_arch = "wasm32"))]
struct Temporary(std::path::PathBuf);
#[cfg(not(target_arch = "wasm32"))]
impl Drop for Temporary {
- fn drop(&mut self) { let _ = std::fs::remove_file(&self.0); }
+ fn drop(&mut self) {
+ let _ = std::fs::remove_file(&self.0);
+ }
}
/// Atomically publish an encoded recovery copy at a **previously unused** name.
@@ -30,8 +32,7 @@ pub fn write_recovery_copy_bytes(destination: &Path, bytes: &[u8]) -> Result<(),
static NEXT: AtomicU64 = AtomicU64::new(0);
let err = |e: std::io::Error| IoError::Unsupported(format!("recovery copy: {e}"));
let parent = destination.parent().filter(|p| !p.as_os_str().is_empty()).unwrap_or(Path::new("."));
- let name = destination.file_name().filter(|n| !n.is_empty()).ok_or_else(||
- IoError::Unsupported("recovery copy needs a valid file name".into()))?;
+ let name = destination.file_name().filter(|n| !n.is_empty()).ok_or_else(|| IoError::Unsupported("recovery copy needs a valid file name".into()))?;
let mut temporary = None;
for _ in 0..64 {
let next = NEXT.fetch_add(1, Ordering::Relaxed);
@@ -49,7 +50,10 @@ pub fn write_recovery_copy_bytes(destination: &Path, bytes: &[u8]) -> Result<(),
opts.mode(0o600);
}
match opts.open(&candidate) {
- Ok(file) => { temporary = Some((Temporary(candidate), file)); break; }
+ Ok(file) => {
+ temporary = Some((Temporary(candidate), file));
+ break;
+ }
Err(e) if e.kind() == std::io::ErrorKind::AlreadyExists => continue,
Err(e) => return Err(err(e)),
}
@@ -82,7 +86,11 @@ mod tests {
#[test]
fn recovered_copy_never_replaces_an_existing_file() {
- let dir = std::env::temp_dir().join(format!("photocraft-copy-{}-{}", std::process::id(), std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).unwrap().as_nanos()));
+ let dir = std::env::temp_dir().join(format!(
+ "photocraft-copy-{}-{}",
+ std::process::id(),
+ std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).unwrap().as_nanos()
+ ));
std::fs::create_dir(&dir).unwrap();
let source = dir.join("original.psd");
let copy = dir.join("copy.psd");
@@ -93,7 +101,8 @@ mod tests {
assert_eq!(std::fs::read(&copy).unwrap(), b"recovered");
assert!(write_recovery_copy_bytes(&copy, b"overwritten").is_err());
assert_eq!(std::fs::read(&copy).unwrap(), b"recovered");
- #[cfg(unix)] {
+ #[cfg(unix)]
+ {
use std::os::unix::fs::symlink;
let link = dir.join("symlink.psd");
symlink(&source, &link).unwrap();
diff --git a/crates/io/tests/support/recovery_psd.rs b/crates/io/tests/support/recovery_psd.rs
index aff1632e2..7febfd94b 100644
--- a/crates/io/tests/support/recovery_psd.rs
+++ b/crates/io/tests/support/recovery_psd.rs
@@ -136,11 +136,8 @@ fn merged_rgb(background: &[Vec<u8>; 3]) -> Vec<u8> {
/// in the green channel of the upper layer; the file is otherwise well framed.
pub fn make_psd(corrupt: bool) -> Vec<u8> {
let background = background_rgb();
- let background_layer = layer(
- "SAFE blue background",
- (0, 0, WIDTH as i32, HEIGHT as i32),
- (0..3).map(|ch| raw_channel(ch, &background[ch as usize])).collect(),
- );
+ let background_layer =
+ layer("SAFE blue background", (0, 0, WIDTH as i32, HEIGHT as i32), (0..3).map(|ch| raw_channel(ch, &background[ch as usize])).collect());
let panel_width = PANEL.2 - PANEL.0;
let panel_height = PANEL.3 - PANEL.1;
diff --git a/crates/ui-egui/src/open_prompt.rs b/crates/ui-egui/src/open_prompt.rs
index 5234297c8..3a86e2019 100644
--- a/crates/ui-egui/src/open_prompt.rs
+++ b/crates/ui-egui/src/open_prompt.rs
@@ -154,7 +154,11 @@ pub fn answer_remembering(app: &mut PhotocraftApp, action: &str) -> Result<Value
_ => "preserve",
};
app.run("edit.colorSettings", json!({key: policy, "askOnMismatch": false}))?;
- let same = |h: &Held| !h.recovery_pending && policy_key(h.doc.mode) == Some(key) && h.question.as_ref().is_some_and(|q| q.get("missing").and_then(Value::as_bool) != Some(true));
+ let same = |h: &Held| {
+ !h.recovery_pending
+ && policy_key(h.doc.mode) == Some(key)
+ && h.question.as_ref().is_some_and(|q| q.get("missing").and_then(Value::as_bool) != Some(true))
+ };
let Some(held) = app.held_opens.pop_front() else { return Err("no file is waiting to open".into()) };
let r = open(app, held, Some(action));
while app.held_opens.front().is_some_and(same) {
@@ -173,33 +177,39 @@ pub(crate) fn recovery_dialog(app: &mut PhotocraftApp, ctx: &egui::Context) {
let Some(front) = app.held_opens.front().filter(|h| h.recovery_pending) else { return };
let (name, warnings) = (front.name.clone(), front.warnings.clone());
let mut choice = None;
- egui::Window::new(tl!("Damaged Photoshop document"))
- .anchor(egui::Align2::CENTER_CENTER, [0.0, 0.0])
- .collapsible(false)
- .resizable(false)
- .show(ctx, |ui| {
- ui.set_max_width(500.0);
- ui.label(format!("{name} contains unreadable layers or image data."));
- ui.label("You can open the recoverable parts, but some pixels or masks may be missing.");
- ui.strong("The original file cannot be overwritten. Save a Copy must use a new file name.");
- for warning in warnings.iter().filter(|w| !w.starts_with("PSD/PSB RECOVERY:")).take(5) {
- ui.label(format!("- {warning}"));
+ egui::Window::new(tl!("Damaged Photoshop document")).anchor(egui::Align2::CENTER_CENTER, [0.0, 0.0]).collapsible(false).resizable(false).show(ctx, |ui| {
+ ui.set_max_width(500.0);
+ ui.label(format!("{name} contains unreadable layers or image data."));
+ ui.label("You can open the recoverable parts, but some pixels or masks may be missing.");
+ ui.strong("The original file cannot be overwritten. Save a Copy must use a new file name.");
+ for warning in warnings.iter().filter(|w| !w.starts_with("PSD/PSB RECOVERY:")).take(5) {
+ ui.label(format!("- {warning}"));
+ }
+ ui.separator();
+ ui.horizontal(|ui| {
+ if ui.button(tl!("Cancel")).clicked() {
+ choice = Some(false);
+ }
+ if ui.button(tl!("Open in Recovery Mode")).clicked() {
+ choice = Some(true);
}
- ui.separator();
- ui.horizontal(|ui| {
- if ui.button(tl!("Cancel")).clicked() { choice = Some(false); }
- if ui.button(tl!("Open in Recovery Mode")).clicked() { choice = Some(true); }
- });
});
- if let Some(accept) = choice { answer_recovery(app, accept); }
+ });
+ if let Some(accept) = choice {
+ answer_recovery(app, accept);
+ }
}
/// Accept or discard the first pending damaged PSD. This is also the modal's testable
/// transition: no document is opened before `accept` is explicitly true.
pub(crate) fn answer_recovery(app: &mut PhotocraftApp, accept: bool) {
- if !app.held_opens.front().is_some_and(|h| h.recovery_pending) { return; }
+ if !app.held_opens.front().is_some_and(|h| h.recovery_pending) {
+ return;
+ }
if accept {
- if let Some(front) = app.held_opens.front_mut() { front.recovery_pending = false; }
+ if let Some(front) = app.held_opens.front_mut() {
+ front.recovery_pending = false;
+ }
} else {
app.held_opens.pop_front();
}