0
約束我有以下代碼:核心特質毯實現由本地定義的公共特質
pub trait GetIdentifier {
//...
}
impl<T: GetIdentifier> Hash for T {
fn hash(&self) -> //....
}
我得到以下錯誤:
error[E0119]: conflicting implementations of trait `std::hash::Hash` for type `&_`:
--> <anon>:18:1
|
18 |/impl<T: GetIdentifier> Hash for T {
19 | | }
| |_^
|
= note: conflicting implementation in crate `core`
error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g. `MyStruct<T>`); only traits defined in the current crate can be implemented for a type parameter
--> <anon>:18:1
|
18 |/impl<T: GetIdentifier> Hash for T {
19 | | }
| |_^
爲什麼?我還沒有爲&_
執行GetIdentifier
,所以的總括不應該適用於&_
。我的箱子的消費者無法執行核心類型GetIdentifier
,所以在那裏沒有問題。我在這裏錯過了什麼?爲什麼&_
甚至在這裏涉及 - 我沒有把?Sized
綁定在我的特質上,所以不應該考慮引用....對嗎?
根據我的理解,OP指出'GetIdentifier'是一個本地特徵,因此不能從外部實現。 –
我認爲這個特質是公開的,因爲否則就不需要區分核心類型和自定義類型 –
@ E_net4我的意思是本地定義的公共特質 - 我將更新問題 – user1935361