3
我嘗試寫一些基本的通用:防鏽:仿製藥PartialEq特質
pub struct MyGeneric<T> {
vec: Vec<T>
}
impl<T> MyGeneric<T> {
fn add(&mut self, item: T) {
if !self.vec.contains(&item) {
self.vec.push(item);
}
}
}
,但得到的錯誤:
priority_set.rs:23:10: 23:35 error: the trait `core::cmp::PartialEq` is not implemented for the type `T`
priority_set.rs:23 if !self.vec.contains(&item) {
^~~~~~~~~~~~~~~~~~~~~~~~~
error: aborting due to previous error
我試圖實現PartialEq在幾個方面尋找到API文件,但沒有找到自己的解決方案。我對性狀概念不是很熟悉,所以我需要幫助。
謝謝。
您能否擴展您的示例代碼?我想我已經開始瞭解,但不太確定。 – bbrodriges 2014-09-25 11:32:25
@ bender.rodriges我已經包含了在Rust 0.11中編譯的最小示例。 – hamstergene 2014-09-25 11:34:33
現在我明白了!我確實認爲符號意味着派生。所有這一次我試圖像fmt :: Show trait一樣實現它。謝謝! –
bbrodriges
2014-09-25 11:38:04