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
相关产品推荐
相关产品推荐

