Rust:找不到宏

我正在尝试从postgres_types文档中运行rust代码。

示例代码可在此处找到:postgres_types

我的防锈环境:

  

cargo --version   货物1.40.0每晚(5da4b4d47 2019-10-28)

     

rustc-版本   rustc 1.40.0-每晚(b520af6fd 2019-11-03)


main.rs

#[cfg(feature = "derive")]
use postgres_types::{ToSql,FromSql};

#[derive(Debug,ToSql,FromSql)]
enum Mood {
    Sad,Ok,Happy,}

fn main() {
    let mood = Mood::Sad;

    println!("{:?}",mood);
}

Cargo.toml

...

[dependencies]
postgres-types = "0.1.0-alpha.1"

当我尝试使用cargo run运行时,我得到:

error: cannot find derive macro `ToSql` in this scope
 --> src\main.rs:4:17
  |
4 | #[derive(Debug,FromSql)]
  |                 ^^^^^

error: cannot find derive macro `FromSql` in this scope
 --> src\main.rs:4:24
  |
4 | #[derive(Debug,FromSql)]
  |                        ^^^^^^^

我在这里做错了什么?显然我缺少基本的东西。我没有正确导入宏吗?

tian150288 回答:Rust:找不到宏

引用文档

  

如果启用了derive货物功能,则可以为自定义Postgres类型派生ToSql和FromSql实现。

要启用derive功能,您需要将其放在Cargo.toml中:

[dependencies]
postgres-types = {version = "0.1.0-alpha.1",features = ["derive"]}
本文链接:https://www.f2er.com/3130619.html

大家都在问