我的代码曾经在夜间工作 - 2016-11-15。当我升级到1.15.1稳定版时,我开始收到一些关于未找到类型实现的错误。这是一个例子:
error[E0277]: the trait bound `errors::Error: core::convert::From<r2d2_postgres::<unnamed>::error::Error>` is not satisfied
--> src/pg/datastore.rs:79:23
|
79 | let results = conn.query("DELETE FROM accounts WHERE id=$1 RETURNING 1", &[&account_id])?;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `core::convert::From<r2d2_postgres::<unnamed>::error::Error>` is not implemented for `errors::Error`
|
= help: the following implementations were found:
= help: <errors::Error as core::convert::From<r2d2_postgres::Error>>
= help: <errors::Error as core::convert::From<postgres::error::Error>>
= help: <errors::Error as core::convert::From<r2d2::GetTimeout>>
= help: <errors::Error as core::convert::From<rocksdb::Error>>
= help: and 3 others
= note: required by `core::convert::From::from`
......即使有相关的From
实施。这是一个缩短版本:
use std::error::Error as StdError;
use r2d2::GetTimeout;
use postgres::error::Error as PostgresError;
use r2d2_postgres::Error as R2D2PostgresError;
use super::fmt;
#[derive(Eq, PartialEq, Clone, Debug)]
pub enum Error {
Unexpected(String),
...
}
impl StdError for Error {
fn description(&self) -> &str {
...
}
fn cause(&self) -> Option<&StdError> {
None
}
}
impl From<R2D2PostgresError> for Error {
fn from(err: R2D2PostgresError) -> Error {
Error::Unexpected(format!("{}", err))
}
}
impl From<PostgresError> for Error {
fn from(err: PostgresError) -> Error {
Error::Unexpected(pg_error_to_description(err))
}
}
impl From<GetTimeout> for Error {
fn from(err: GetTimeout) -> Error {
Error::Unexpected(format!("Could not fetch connection: {}", err))
}
}
我认为这与使用相关类型有关,因为它似乎不会在其他环境中发生。此外,命名空间r2d2_postgres::<unnamed>::error::Error
没有意义 - 什么是<unnamed>
?这是the relevant type association。
答案 0 :(得分:2)
原来这是由于版本冲突造成的。我已切换到postgres
的主分支以修复单独的版本冲突,但r2d2_postgres
引用了不同版本的postgres
。
幸运的是,正如this issue中所述,Cargo.toml
有一个[replace]
部分,可让您像这样处理它:
[replace]
"postgres:0.13.6" = { git = "https://github.com/sfackler/rust-postgres" }