I use a library, which is full of generics.
Here is the description of the function which uses 3 type parameters:
impl<F, R, C> CreateTexture<TextureContext<F, R, C>> for Texture<R> where
C: Buffer<R>,
F: Factory<R>,
R: Resources,
In a normal code I write it like this:
let mut texture_context = window.create_texture_context();
let texture: pw::G2dTexture = pw::Texture::from_image(
&texture_context
....
).unwrap();
And it works as magic.
Now I want to move this call (creation of a new texture) into a trait for my image (buffer) type. I need to specify type for texture_context
. If I write something like that:
pub fn as_texture(self, texture_context: & mut pw::TextureContext) {
...
It does not work: expected 3 type arguments
.
But I have no idea what are the types for texture_context
in a normal code (let mut texture_context = window.create_texture_context();
). It all done automatically.
I would like to copy type of texture_context
into function signature, but I have no idea how to see it in the code. I got used to dynamically typed languages, where I can pry and look, or just print(type(foo))
, but Rust does not support this.
Are there any tricks to see the the exact type for an value/variable with inferred type?