構造体にピストンテクスチャを格納しようとしています。私は実際にこれが何であるかの種類を気にしない ジェネリック構造体のコンストラクタの "Expected type parameter"エラー
gfx_device_gl::Resources
implements gfx::Resources
src/main.rs:37:9: 39:10 error: mismatched types:
expected `TextureFactory<R>`,
found `TextureFactory<gfx_device_gl::Resources>`
(expected type parameter,
found enum `gfx_device_gl::Resources`)
はかかわらず、私はそう知っている必要があります(私はそれだけで、デバイス固有の実装だと思います。):
struct TextureFactory<R> where R: gfx::Resources {
block_textures: Vec<Rc<Texture<R>>>,
}
impl<R> TextureFactory<R> where R: gfx::Resources {
fn new(window: PistonWindow) -> Self {
let texture = Rc::new(gfx_texture::Texture::from_path(
&mut *window.factory.borrow_mut(),
"assets/element_red_square.png",
Flip::None, &TextureSettings::new()
).unwrap());
let block_textures = Vec::new();
block_textures.push(texture);
TextureFactory {
block_textures: block_textures,
}
}
}
これはコンパイルされません。私はそれを構造体に格納することができます。
私はcompilable repo on Githubを作った。
(。私はRust generics/traits: "expected 'Foo<B>', found 'Foo<Foo2>'"が同じ質問ですが、私は私の問題に適用する方法を見つけ出すことができない疑いがある)
可能な複製http://stackoverflow.com/questions/31490913/rust-generics-expected-t-found-fooまたはhttp://stackoverflow.com/questions/31060851/generics-error-expected-type- parameter-found-struct – Shepmaster
[trait objects](http://doc.rust-lang.org/book/trait-objects.html)を使用して、コードに含まれる多様性を達成することができます。 – cheme