1
我有用於每晚工作的代碼 - 2016-11-15。當我升級到1.15.1 stable時,我開始發現一些關於未找到類型實現的錯誤。這裏有一個例子:無法找到關聯類型的特徵實現
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。
對不起,我很擔心,這個問題已經變得太羅嗦了,那答案可能對別人很明顯。我會更充實。 – ysimonson
在提交代碼並進行編譯之後(添加外部條目,實現'Display',更正導入,刪除'...'等等 - 所有跡象表明您沒有在本地測試此代碼)代碼編譯時沒有你說的錯誤。在你提供[MCVE]之前,你很難得到任何有用的幫助。具體來說,如果有人可以直接從您的問題中複製,然後將其粘貼到本地,並獲取相同的錯誤消息,則最有可能得到答案。 – Shepmaster
@Shepmaster如您在刪除您的評論之前所進行的對話中所述,我一直無法創建一個最簡單的示例。總的來說,這個問題很難解決,因爲它是不是開放源代碼的大型代碼庫的一部分。我會留下評論,但是爲什麼我爲後人修復了它。 – ysimonson