-1
use raylib::prelude::*;

fn main() {
    let (mut rl, thread) = raylib::init().size(640, 480).title("Hello, World").build();

    while !rl.window_should_close() {
        let mut d = rl.begin_drawing(&thread);

        d.load_texture(&d, "./assets/Grass.png"); // error here
        d.clear_background(Color::BLACK);
    }
}

mismatched types expected reference &RaylibThread found reference &RaylibDrawHandle<'_>rustcClick for full compiler diagnostic main.rs(12, 11): arguments to this function are incorrect texture.rs(856, 12): associated function defined here

I figure i borrow the reference by doing &d Maybe im missing something. I'm a bit confused on how to proceed.

BARNOWL
  • 3,326
  • 10
  • 44
  • 80

2 Answers2

1

The load_texture function expects a reference to a RaylibThread as first argument, but you are passing in a reference to a RaylibDrawHandle.

Therefore you will need to change the line with the error to:

d.load_texture(&thread, "./assets/Grass.png");
frankenapps
  • 5,800
  • 6
  • 28
  • 69
  • this makes sense, but i get this ```cannot borrow data in dereference of `RaylibDrawHandle<'_>` as mutable trait `DerefMut` is required to modify through a dereference, but it is not implemented for `RaylibDrawHandle<'_>``` – BARNOWL Aug 16 '23 at 04:26
0

With the help of the answer i was able to resolve the issue, i guess i had to move this line before the while loop

use raylib::prelude::*;

fn main() {
    let (mut rl, thread) = raylib::init().size(640, 480).title("Hello, World").build();
    let texture = rl.load_texture(&thread, "./assets/Grass.png");
    texture.unwrap();
    while !rl.window_should_close() {
        let mut d = rl.begin_drawing(&thread);

        d.clear_background(Color::BLACK);
    }
}
BARNOWL
  • 3,326
  • 10
  • 44
  • 80