Piston Text::Draw error

I’ve got drawing text working when it’s in the window draw closure, but when I move it to a function, I get a weird error that I can’t seem to resolve. I’ve tried a few things, such as specify the generic type as noted in the error, but that large thing is also in error. I have use piston_window::*, so I’m not sure if something is missing. Code snippet below. Error is in the “text” function on .draw. Error message below that.

pub fn render(&mut self, window : &mut PistonWindow, event : &Event) {

    window.draw_2d(event, |context, graphics| {
        clear( [0.0, 0.0, 0.0, 1.0], graphics);

        for c in &self.characters {                                
            c.draw(&context, graphics);
        }
        
        let transform = context.transform.trans(100.0, 100.0);
        Text::new_color([1.0, 1.0, 1.0, 1.0], 14)
            .draw("Something", &mut self.glyphs, &context.draw_state, transform, graphics).unwrap();
        
        self.text("Something", 100.0, 100.0, &context, graphics);
    });


}

fn text<G : Graphics>(&mut self, t : &str, x : f64, y : f64, context : &Context, graphics: &mut G){
    let transform = context.transform.trans(x, y);
    Text::new_color([1.0, 1.0, 1.0, 1.0], 14)
        .draw(t,&mut self.glyphs, &context.draw_state, transform, graphics).unwrap();
}

error[E0271]: type mismatch resolving <G as graphics::graphics::Graphics>::Texture == gfx_texture::Texture<gfx_device_gl::Resources>
–> src\game\mod.rs:111:14
|
111 | .draw(t,&mut self.glyphs, &context.draw_state, transform, graphics).unwrap();
| ^^^^ expected associated type, found struct gfx_texture::Texture
|
= note: expected type <G as graphics::graphics::Graphics>::Texture
found type gfx_texture::Texture<gfx_device_gl::Resources>

You can change your definition to the following:

fn text<G : Graphics<Texture=gfx_texture::Texture<gfx_device_gl::Resources>>>(&mut self, t : &str, x : f64, y : f64, context : &Context, graphics: &mut G){
    let transform = context.transform.trans(x, y);
    Text::new_color([1.0, 1.0, 1.0, 1.0], 14)
        .draw(t,&mut self.glyphs, &context.draw_state, transform, graphics).unwrap();
}

Or alternatively, define a type alias to make it shorter:

type GraphicsTexture = gfx_texture::Texture<gfx_device_gl::Resources>;
fn text<G : Graphics<Texture=GraphicsTexture>>(&mut self, t : &str, x : f64, y : f64, context : &Context, graphics: &mut G){
    let transform = context.transform.trans(x, y);
    Text::new_color([1.0, 1.0, 1.0, 1.0], 14)
        .draw(t,&mut self.glyphs, &context.draw_state, transform, graphics).unwrap();
}

I tried putting in the suggested association before and it didn’t work. I put in you shorter suggestion and I get these errors now:

error: expected one of !, +, ::, or ;, found >
–> src\game\mod.rs:108:70
|
108 | type GraphicsTexture = gfx_texture::Texture<gfx_device_gl::Resources>>;
| ^ expected one of !, +, ::, or ; here

error[E0412]: cannot find type GraphicsTexture in this scope
–> src\game\mod.rs:109:30
|
109 | fn text<G : Graphics<Texture=GraphicsTexture>>(&mut self, t : &str, x : f64, y : f64, context : &Context, graphics: &mut G){
| ^^^^^^^^^^^^^^^ not found in this scope

I feel like i"m missing a use or something, but I don’t know what.

I keep forgetting to mention that this is my first Rust program (yes, probably a bit ambitious to start with a crate like Piston).

Also thanks!

Whoops sorry my bad, I made a typo, and I added another angle bracket onto the end of the type alias

Ah I see it, and removed it. Now I get:
error[E0433]: failed to resolve: use of undeclared type or module gfx_texture
–> src\game\mod.rs:108:28
|
108 | type GraphicsTexture = gfx_texture::Texture<gfx_device_gl::Resources>;
| ^^^^^^^^^^^ use of undeclared type or module gfx_texture

error[E0433]: failed to resolve: use of undeclared type or module gfx_device_gl
–> src\game\mod.rs:108:49
|
108 | type GraphicsTexture = gfx_texture::Texture<gfx_device_gl::Resources>;
| ^^^^^^^^^^^^^ use of undeclared type or module gfx_device_gl

error[E0412]: cannot find type GraphicsTexture in this scope
–> src\game\mod.rs:109:34
|
109 | fn text<G : Graphics<Texture=GraphicsTexture>>(&mut self, t : &str, x : f64, y : f64, context : &Context, graphics: &mut G){
| ^^^^^^^^^^^^^^^ not found in this scope

error[E0202]: associated types are not yet supported in inherent impls (see #8995)
–> src\game\mod.rs:108:5
|
108 | type GraphicsTexture = gfx_texture::Texture<gfx_device_gl::Resources>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 4 previous errors

This is usually where I run out of useful google results and revert back to where I only have 1 error.

Hmm, that’s a bit odd, what version of gfx are you using (Cargo.toml)
Also, please post code and backtraces/errors within code fences:

```
Your code
```

Here’s all my dependencies. Should I only have a “piston” reference here, and not the sub parts? They may have collected over various attempts.

[dependencies]
piston = "0.42.0"
piston_window = "0.81.0"
piston2d-graphics = "0.30.0"
find_folder = "0.3.0"
serde = { version = "1.0.90", features = ["derive"] }
serde_json = "1.0"

It’s been a week, so I’m assuming that’s pretty much it? Since I’ve been stuck for a week, I’m not sure what to do next.

Thanks to Optimistic-Peach for trying to help out.