我从 Rust 开始,因为我需要它用于一个项目,我尝试过 watchexec,但当我尝试 watchexec 示例时什么都不做,有一些错误,当我尝试用建议纠正它时,总是错误,有人可以帮助我吗?
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(())
}
这是我的
cargo compille --all-features
错误:
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
我在 unwrap() 和 Expect("") 之前尝试了 as_ref() 字段
它已正确编译,谢谢
我是 Rust 新手,它与 Python 完全不同!