小编cov*_*sh2的帖子

为什么我得到错误"特征`Foo`没有为`&mut T`实现",即使T实现了特性?

我有这个来源:

pub fn draw<G, C>(&self, font: &mut C, draw_state: &DrawState, transform: Matrix2d, g: &mut G)
where
    C: CharacterCache,
    G: Graphics<Texture = <C as CharacterCache>::Texture>,
{
    self.properties.draw(
        self.text.as_str(),
        &mut font,
        &draw_state,
        transform,
        g,
    );
}
Run Code Online (Sandbox Code Playgroud)

而错误

the trait bound `&mut C: graphics::character::CharacterCache` is not satisfied 
(the trait `graphics::character::CharacterCache` is not implemented for `&mut C`) 
Run Code Online (Sandbox Code Playgroud)

C定义的唯一方面是它实现CharacterCache,但错误说明相反.

DrawState,Matrix2d,CharacterCache和其实施方式中,Texture和self.properties( Text)由活塞2D图形库提供.总的来说,一定有关于特征的东西我误解了.

Text::draw函数签名:

fn draw<C, G>(
    &self,
    text: &str,
    cache: &mut C,
    draw_state: …
Run Code Online (Sandbox Code Playgroud)

traits rust associated-types

7
推荐指数
2
解决办法
2617
查看次数

标签 统计

associated-types ×1

rust ×1

traits ×1