未实施特征以参考特征

时间:2018-03-31 11:07:37

标签: rust

我收到这个编译器错误,我不理解也不知道如何修复:

error[E0277]: the trait bound `&'a mut Runnable + 'a: Runnable` is not satisfied
  --> src/main.rs:11:9
   |
11 |         &mut self.runnables[id]
   |         ^^^^^^^^^^^^^^^^^^^^^^^ the trait `Runnable` is not implemented for `&'a mut Runnable + 'a`
   |
   = note: required for the cast to the object type `Runnable + 'a`

我已将代码简化为:

pub trait Runnable {
    fn name(&self) -> &str;
}

pub struct RunList<'a> {
    runnables: Vec<&'a mut Runnable>,
}

impl<'a> RunList<'a> {
    pub fn get(&self, id: usize) -> &'a mut Runnable {
        &mut self.runnables[id]
    }
}

fn main() {}

Playground

0 个答案:

没有答案