Rust:找不到宏
Rust: cannot find macro
我正在尝试 运行 从 postgres_types
文档中提取代码。
示例代码可以在这里找到:postgres_types
我的 Rust 环境:
cargo --version
cargo 1.40.0-nightly (5da4b4d47 2019-10-28)
rustc --version
rustc 1.40.0-nightly (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, ToSql, FromSql)]
| ^^^^^
error: cannot find derive macro `FromSql` in this scope
--> src\main.rs:4:24
|
4 | #[derive(Debug, ToSql, FromSql)]
| ^^^^^^^
我在这里做错了什么?显然我缺少一些基本的东西。我没有正确导入宏吗?
引用文档,
If the derive
cargo feature is enabled, you can derive ToSql and FromSql implementations for custom Postgres types.
要启用 derive
功能,您需要将其放入 Cargo.toml
:
[dependencies]
postgres-types = {version = "0.1.0-alpha.1", features = ["derive"]}
我正在尝试 运行 从 postgres_types
文档中提取代码。
示例代码可以在这里找到:postgres_types
我的 Rust 环境:
cargo --version cargo 1.40.0-nightly (5da4b4d47 2019-10-28)
rustc --version rustc 1.40.0-nightly (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, ToSql, FromSql)]
| ^^^^^
error: cannot find derive macro `FromSql` in this scope
--> src\main.rs:4:24
|
4 | #[derive(Debug, ToSql, FromSql)]
| ^^^^^^^
我在这里做错了什么?显然我缺少一些基本的东西。我没有正确导入宏吗?
引用文档,
If the
derive
cargo feature is enabled, you can derive ToSql and FromSql implementations for custom Postgres types.
要启用 derive
功能,您需要将其放入 Cargo.toml
:
[dependencies]
postgres-types = {version = "0.1.0-alpha.1", features = ["derive"]}