标签: anyhow

为什么在稳定版本中无论如何都不能工作?

我有一个干净的项目,无论如何我都将 1.0.66 包含在其中。安装了最新版本的 Rust。我收到一条错误消息,说无论如何都需要夜间版本。也许这是由于使用了 backtrace,但 Rust 版本 1.65 中支持它。我不明白如何解决这个问题。

Cargo.toml

[package]
name = "libfs"
version = "0.1.0"
edition = "2021"
[dependencies]
tokio = {version = "1.22", features = ["full"]}
anyhow = {version = "1.0.66", features = ["default"]}
Run Code Online (Sandbox Code Playgroud)

src/lib.rs

#[tokio::test]
async fn run_test() {
    println!("test");
}

Run Code Online (Sandbox Code Playgroud)

输出

$ cargo build
   Compiling anyhow v1.0.66
error[E0554]: `#![feature]` may not be used on the stable release channel
   --> /home/dima/.cargo/registry/src/github.com-1ecc6299db9ec823/anyhow-1.0.66/src/lib.rs:214:32
    |
214 | #![cfg_attr(backtrace, feature(error_generic_member_access, provide_any))]
    |                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0554]: `#![feature]` may not be used on …
Run Code Online (Sandbox Code Playgroud)

rust anyhow

9
推荐指数
1
解决办法
1992
查看次数

Rust 编译器似乎对 Result 类型感到困惑

我正在尝试编译如下内容:

use anyhow::Result;
use std::sync::{mpsc, Mutex, OnceLock};
use std::cell::Cell;
use std::fmt;

static COMS: OnceLock<Mutex<Coms>> = OnceLock::new();

struct Coms {
    tx: Cell<Option<mpsc::Sender<Msg>>>,
    rx: Cell<Option<mpsc::Receiver<Msg>>>,
}

enum Msg {}

fn bar() -> Result<()> {
    let (tx, rx) = mpsc::channel();
    COMS.set(
        Mutex::new(
            Coms {
                tx: Cell::new(Some(tx)),
                rx: Cell::new(Some(rx)),
            }
        )
    );
    //)?;
    Ok(())
}

fn main() {
    let _ = bar();
}
Run Code Online (Sandbox Code Playgroud)

我收到有关未使用结果的预期警告:

warning: unused `Result` that must be used
  --> src/main.rs:17:5
   |
17 | /     COMS.set(
18 | |         Mutex::new(
19 | …
Run Code Online (Sandbox Code Playgroud)

rust anyhow

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

标签 统计

anyhow ×2

rust ×2