我正在使用Piston和Sprite進行個人項目。該example code調用此方法:調用sprite :: Scene ::時出現類型不匹配:: draw
scene.draw(c.transform, g);
我試圖調用繪製一切的方法。 我第一次嘗試:
draw<G: Graphics>(&self, c: &Context, g: &mut G, scene: &mut Scene)
那麼編譯器告訴我,我需要給一個類型參數的Scene
所以我嘗試這樣的:
draw<G: Graphics, S>(&self, c: &Context, g: &mut G, scene: &mut Scene<S>)
那麼編譯器告訴我,該類型需要工具特點ImageSize
所以我嘗試這樣的:
draw<G: Graphics, S: ImageSize>(&self, c: &Context, g: &mut G, scene: &mut Scene<S>)
然後我得到這個錯誤:
error[E0271]: type mismatch resolving `<G as graphics::Graphics>::Texture == S`
--> src/game.rs:38:15
|
38 | scene.draw(c.transform, g);
| ^^^^ expected associated type, found type parameter
|
= note: expected type `<G as graphics::Graphics>::Texture`
found type `S`
我不明白編譯器試圖在這裏說什麼。 Scene
的完整類型是sprite::Scene<piston_window::Texture<gfx_device_gl::Resources>>
但我不想在該方法的簽名中寫入該類型。
我有兩個問題,那麼:
- 什麼是編譯器試圖告訴我嗎?
- 如何將場景傳遞給方法?