【发布时间】:2021-10-19 03:07:20
【问题描述】:
所以我正在学习如何使用 Rust 构建 REST API。尝试实现以下行时,我不断收到错误消息:
#[derive(Deserialize, Debug)]
pub struct Config {
pub pg: deadpool_postgres::Config,
pub server: ServerConfig,
}
这是我得到的错误代码:
error[E0277]: the trait bound `deadpool_postgres::Config:
config::_::_serde::Deserialize<'_>` is not satisfied
这是我在 Cargo.toml 中的依赖项:
[dependencies]
actix-rt = "2.3.0"
actix-web = "3.3.2"
serde = "1.0.130"
dotenv = "0.15.0"
config = "0.11.0"
tokio-pg-mapper = "0.2.0"
tokio-pg-mapper-derive = "0.2.0"
deadpool-postgres = "0.10.0"
tokio-postgres = "0.7.3"
我是 Rust 的新手,我不确定错误的含义或修复它的方法。我正在实现 deadpool_postgres 就像它在文档中一样,除了在我的文件中我试图从 dotenv 文件中提取数据库变量。这是完整的文件:
use::config::ConfigError;
use serde::Deserialize;
#[derive(Deserialize, Debug)]
pub struct Config {
pub pg: deadpool_postgres::Config,
pub server: ServerConfig,
}
#[derive(Deserialize, Debug)]
pub struct ServerConfig {
pub host: String,
pub port: i32
}
impl Config {
pub fn from_env() -> Result<Self, ConfigError> {
let mut cfg = config::Config::new();
cfg.merge(config::Environment::new())?;
cfg.try_into()
}
}
【问题讨论】:
标签: rust