我对无论如何都是新手,我想知道是否有办法将无论如何错误转换为标准错误
fn m() {
let a: anyhow::Result<String> = Ok("".into());
n(a);
}
fn n(r: std::result::Result<String, impl std::error::Error>) {
println!("{:?}", r);
}
Run Code Online (Sandbox Code Playgroud)
error[E0277]: the trait bound `anyhow::Error: std::error::Error` is not satisfied
--> src\main.rs:82:7
|
82 | n(a);
| - ^ the trait `std::error::Error` is not implemented for `anyhow::Error`
| |
| required by a bound introduced by this call
Run Code Online (Sandbox Code Playgroud) 我正在尝试寻找适用于 PowerShell 的TOML文件解析器。
我在PowerShell 库或预安装的 PowerShell 函数中找不到任何有关它的信息。
我设置超时为1s,但是任务执行到3s,却没有发生panic。
#代码
#[should_panic]
fn test_timeout() {
let rt = create_runtime();
let timeout_duration = StdDuration::from_secs(1);
let sleep_duration = StdDuration::from_secs(3);
let _guard = rt.enter();
let timeout = time::timeout(timeout_duration, async {
log("timeout running");
thread::sleep(sleep_duration);
log("timeout finsihed");
"Ding!".to_string()
});
rt.block_on(timeout).unwrap();
}
Run Code Online (Sandbox Code Playgroud)