Rust DList实现了Deque?

时间:2014-07-13 17:46:10

标签: rust traits

collections::dlist::DList希望实施collections::Deque,其中push_back方法。

但是编译这个简单的程序:

extern crate collections;

fn main () {
    let mut c : collections::dlist::DList<int> = collections::dlist::DList::new();
    c.push_back(1);
}

给出了这个错误消息

try.rs:5:4: 5:16 error: type `collections::dlist::DList<int>` does not implement any method in scope named `push_back`
try.rs:5    c.push_back(1);
              ^~~~~~~~~~~~

1 个答案:

答案 0 :(得分:4)

必须导入特征才能使其方法可用。这也在文档中注明:

  

DList实现特质Deque。它应该与use collections::Deque一起导入。