I begin in Rust because I need it for a project, I have try watchexec, and nothing to done when I try the watchexec example there is some errors, when I try to correct it with the suggestion, always errors, could someone help me?
use miette::{IntoDiagnostic, Result};
use watchexec::Watchexec;
#[tokio::main]
async fn main() -> Result<()> {
let wx = Watchexec::new(|mut action| {
// you don't HAVE to spawn jobs:
// here, we just print out the events as they come in
for event in action.events.iter() {
eprintln!("{event:?}");
}
// quit when we get a signal
if action.signals().next().is_some() {
eprintln!("[Quitting...]");
action.quit();
}
action
})?;
// start the engine
let main = wx.expect("REASON").mainf();
// and watch all files in the current directory:
wx.unwrap().config.pathset(["."]);
let _ = main.await.into_diagnostic()?;
Ok(())
}
Here is my cargo compille --all-features errors:
dewachen@monordi:~/eclipse-workspace/w-hdom$ cargo build --all-features
Compiling w-hdom v0.1.0 (/home/dewachen/eclipse-workspace/w-hdom)
error[E0382]: use of moved value: `wcs`
--> src/main.rs:26:2
|
6 | let wcs = Watchexec::new(|mut action| {
| --- move occurs because `wcs` has type `Result<Arc<Watchexec>, CriticalError>`, which does not implement the `Copy` trait
...
23 | let main = wcs.expect("REASON").mainf();
| --- ---------------- `wcs` moved due to this method call
| |
| help: consider calling `.as_ref()` or `.as_mut()` to borrow the type's contents
...
26 | wcs.unwrap().config.pathset(["."]);
| ^^^ value used here after move
|
note: `Result::<T, E>::expect` takes ownership of the receiver `self`, which moves `wcs`
--> /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/result.rs:1024:19
help: you could `clone` the value and consume it, if the `CriticalError: Clone` trait bound could be satisfied
|
23 | let main = wcs.clone().expect("REASON").mainf();
| ++++++++
For more information about this error, try `rustc --explain E0382`.
error: could not compile `w-hdom` (bin "w-hdom") due to 1 previous error
dewachen@monordi:~/eclipse-workspace/w-hdom$ cargo build --all-features
Blocking waiting for file lock on build directory
Compiling w-hdom v0.1.0 (/home/dewachen/eclipse-workspace/w-hdom)
error[E0382]: use of moved value: `wx`
--> src/main.rs:26:2
|
6 | let wx = Watchexec::new(|mut action| {
| -- move occurs because `wx` has type `Result<Arc<Watchexec>, CriticalError>`, which does not implement the `Copy` trait
...
23 | let main = wx.expect("REASON").mainf();
| -- ---------------- `wx` moved due to this method call
| |
| help: consider calling `.as_ref()` or `.as_mut()` to borrow the type's contents
...
26 | wx.unwrap().config.pathset(["."]);
| ^^ value used here after move
|
note: `Result::<T, E>::expect` takes ownership of the receiver `self`, which moves `wx`
--> /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/result.rs:1024:19
help: you could `clone` the value and consume it, if the `CriticalError: Clone` trait bound could be satisfied
|
23 | let main = wx.clone().expect("REASON").mainf();
| ++++++++
For more information about this error, try `rustc --explain E0382`.
error: could not compile `w-hdom` (bin "w-hdom") due to 1 previous error
dewachen@monordi:~/eclipse-workspace/w-hdom$ cargo build --all-features
Blocking waiting for file lock on build directory
Compiling w-hdom v0.1.0 (/home/dewachen/eclipse-workspace/w-hdom)
error[E0599]: no method named `expect` found for struct `Arc<Watchexec>` in the current scope
--> src/main.rs:23:16
|
23 | let main = wx.expect("REASON").mainf();
| ^^^^^^ method not found in `Arc<Watchexec>`
error[E0599]: no method named `unwrap` found for struct `Arc<Watchexec>` in the current scope
--> src/main.rs:26:5
|
26 | wx.unwrap().config.pathset(["."]);
| ^^^^^^ method not found in `Arc<Watchexec>`
error[E0277]: the trait bound `CriticalError: Diagnostic` is not satisfied
--> src/main.rs:20:4
|
20 | })?;
| ^ the trait `Diagnostic` is not implemented for `CriticalError`
|
= help: the following other types implement trait `Diagnostic`:
MietteError
InstallError
MietteDiagnostic
= note: required for `ErrReport` to implement `From<CriticalError>`
= note: required for `Result<(), ErrReport>` to implement `FromResidual<Result<Infallible, CriticalError>>`
warning: unused import: `IntoDiagnostic`
--> src/main.rs:1:14
|
1 | use miette::{IntoDiagnostic, Result};
| ^^^^^^^^^^^^^^
|
= note: `#[warn(unused_imports)]` on by default
Some errors have detailed explanations: E0277, E0599.
For more information about an error, try `rustc --explain E0277`.
warning: `w-hdom` (bin "w-hdom") generated 1 warning
error: could not compile `w-hdom` (bin "w-hdom") due to 3 previous errors; 1 warning emitted
i went to try the as_ref() field before unwrap() and before expect("")
and it has compile correctly, thanks
i'm new in rust, and it is completely different from python!