Repository: Canop/broot (language: rust)

Issue:
Does not compile on Termux (Android) any more
Since #803 introduced a dependency on the `trash` crate, broot does not compile any more, presumably because Android does not have a trash.

```
error[E0433]: failed to resolve: use of undeclared crate or module `platform`
  --> /data/data/com.termux/files/home/.cargo/registry/src/index.crates.io-6f17d22bba15001f/trash-3.3.1/src/lib.rs:67:35
   |
67 |         Self { platform_specific: platform::PlatformTrashContext::new() }
   |                                   ^^^^^^^^ use of undeclared crate or module `platform`

error[E0433]: failed to resolve: use of undeclared crate or module `platform`
  --> /data/data/com.termux/files/home/.cargo/registry/src/index.crates.io-6f17d22bba15001f/trash-3.3.1/src/lib.rs:63:24
   |
63 |     platform_specific: platform::PlatformTrashContext,
   |                        ^^^^^^^^ use of undeclared crate or module `platform`

For more information about this error, try `rustc --explain E0433`.
error: could not compile `trash` (lib) due to 2 previous errors
```

Ideally trash support would be behind a feature so that there is a way to opt out of this feature on platforms which do not have a trash. The feature could be on by default since most major platforms do, but at least it would be easy to make builds on platforms that do not.


Discussion / hints:
> Ideally trash support would be behind a feature so that there is a way to opt out of this feature on platforms which do not have a trash. The feature could be on by default since most major platforms do, but at least it would be easy to make builds on platforms that do not.

This looks good. Do you prefer to make a PR or that I do it ?
Cool, thanks for your support. I can make a PR when I get some time.

Fix patch:
diff --git a/Cargo.toml b/Cargo.toml
index 936db4ef..d7728de0 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -17,8 +17,10 @@ exclude = ["website", "broot*.zip"]
 
 [features]
 default = []
+
 clipboard = ["terminal-clipboard"]
 kitty-csi-check = ["xterm-query"]
+trash = ["dep:trash"]
 
 [dependencies]
 ahash = { version = "0.8.3", features = ["serde"] }
@@ -62,7 +64,7 @@ termimad = "0.29.2"
 terminal-clipboard = { version = "0.4.1", optional = true }
 terminal-light = "1.4.0"
 toml = "0.8"
-trash = "3.1.2"
+trash = { version = "3.1.2", optional = true }
 umask = "2.1.0"
 unicode-width = "0.1.10"
 which = "4.4.0"
diff --git a/compile-all-targets.sh b/compile-all-targets.sh
index cd460cdb..eb509c93 100755
--- a/compile-all-targets.sh
+++ b/compile-all-targets.sh
@@ -50,7 +50,7 @@ cross_build "ARM 32" "armv7-unknown-linux-gnueabihf" ""
 cross_build "ARM 32 MUSL" "armv7-unknown-linux-musleabi" ""
 cross_build "ARM 64" "aarch64-unknown-linux-gnu" ""
 cross_build "ARM 64 MUSL" "aarch64-unknown-linux-musl" ""
-cross_build "Windows" "x86_64-pc-windows-gnu" "clipboard"
+cross_build "Windows" "x86_64-pc-windows-gnu" "clipboard,trash"
 # cross_build "Android" "aarch64-linux-android" "clipboard" Doesn't work anymore - See https://github.com/Canop/broot/issues/565
 
 
diff --git a/src/browser/browser_state.rs b/src/browser/browser_state.rs
index ad9a6a2a..82dbb49a 100644
--- a/src/browser/browser_state.rs
+++ b/src/browser/browser_state.rs
@@ -632,6 +632,8 @@ impl PanelState for BrowserState {
             Internal::trash => {
                 let path = self.displayed_tree().selected_line().path.to_path_buf();
                 info!("trash {:?}", &path);
+
+                #[cfg(feature = "trash")]
                 match trash::delete(&path) {
                     Ok(()) => CmdResult::RefreshState { clear_cache: true },
                     Err(e) => {
@@ -639,6 +641,9 @@ impl PanelState for BrowserState {
                         CmdResult::DisplayError(format!("trash error: {:?}", &e))
                     }
                 }
+
+                #[cfg(not(feature = "trash"))]
+                CmdResult::DisplayError("feature not enabled or platform does not support trash".into())
             }
             Internal::quit => CmdResult::Quit,
             _ => self.on_internal_generic(
diff --git a/src/stage/stage_state.rs b/src/stage/stage_state.rs
index 0c704186..f1186b0f 100644
--- a/src/stage/stage_state.rs
+++ b/src/stage/stage_state.rs
@@ -496,6 +496,8 @@ impl PanelState for StageState {
             }
             Internal::trash => {
                 info!("trash {} staged files", app_state.stage.len());
+
+                #[cfg(feature = "trash")]
                 match trash::delete_all(app_state.stage.paths()) {
                     Ok(()) => CmdResult::RefreshState { clear_cache: true },
                     Err(e) => {
@@ -503,6 +505,9 @@ impl PanelState for StageState {
                         CmdResult::DisplayError(format!("trash error: {:?}", &e))
                     }
                 }
+
+                #[cfg(not(feature = "trash"))]
+                CmdResult::DisplayError("feature not enabled or platform does not support trash".into())
             }
             _ => self.on_internal_generic(
                 w,


Test patch: