小编los*_*sof的帖子

如何将无论如何错误转换为标准错误?

我对无论如何都是新手,我想知道是否有办法将无论如何错误转换为标准错误

代码

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)

rust

6
推荐指数
1
解决办法
4003
查看次数

PowerShell中有解析TOML文件的模块吗?

我正在尝试寻找适用于 PowerShell 的TOML文件解析器。

我在PowerShell 库或预安装的 PowerShell 函数中找不到任何有关它的信息。

powershell toml

5
推荐指数
1
解决办法
2015
查看次数

为什么任务超时时不恐慌?

我设置超时为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)

rust rust-tokio

2
推荐指数
1
解决办法
709
查看次数

标签 统计

rust ×2

powershell ×1

rust-tokio ×1

toml ×1