You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Rust中r2d2_postgres启用chrono特性遇配置报错求助

解决r2d2_postgres依赖feature配置错误的问题

错误原因

你尝试在r2d2_postgres的features中直接指定传递依赖postgres的with-chrono-0_4 feature,但Cargo不允许这种写法——只有当直接依赖在自身的[features]表中重新导出了传递依赖的feature时,才能通过直接依赖的features字段启用。而r2d2_postgres并没有做这个导出,所以报错。

正确配置方式

直接在Cargo.toml中声明postgres依赖并启用with-chrono-0_4 feature,Cargo会确保r2d2_postgres使用这个带feature的postgres版本:

postgres = { version = "0.19", features = ["with-chrono-0_4"] }
r2d2_postgres = "0.18"

说明

这样配置后,postgres crate会包含chrono类型的FromSql/ToSql实现,r2d2_postgres基于这个postgres版本构建,你就能正常使用对应的FromSql trait了。运行cargo build验证即可。

内容的提问来源于stack exchange,提问作者Code4R7

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.24 10:36:24