【发布时间】:2018-05-24 10:42:58
【问题描述】:
我有这个来源:
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,
);
}
还有错误
the trait bound `&mut C: graphics::character::CharacterCache` is not satisfied
(the trait `graphics::character::CharacterCache` is not implemented for `&mut C`)
C 唯一定义的方面是它实现了CharacterCache,但错误却相反。
DrawState、Matrix2d、CharacterCache 及其实现、Texture 和 self.properties (Text) 由 Piston 2d 图形库提供。总的来说,我对特征的理解一定有一些东西。
Text::draw 函数签名:
fn draw<C, G>(
&self,
text: &str,
cache: &mut C,
draw_state: &DrawState,
transform: Matrix2d,
g: &mut G,
) where
C: CharacterCache,
G: Graphics<Texture = C::Texture>,
【问题讨论】:
标签: rust traits associated-types