[英]cannot borrow `win` as immutable because it is also borrowed as mutable
I am getting a cannot borrow win
as immutable because it is also borrowed as mutable as the commented line我得到了一个不能借用的win
作为不可变的,因为它也被借用与注释行一样可变
let (mut win, thread) = raylib::init().size(800, 600).title("Demo").build();
// error at borrowing win
draw.draw_rectangle(
// here
win.get_screen_width() / 2,
0,
5,
// and here
win.get_screen_height(),
Color::WHITE,
);
I think there are two possibility (you do not provide enough ressources to test it in my workspace so it is just supposition):我认为有两种可能性(您没有提供足够的资源来在我的工作区中对其进行测试,所以这只是假设):
Save length before calling:调用前保存长度:
let (mut win, thread) = raylib::init().size(800, 600).title("Demo").build();
let width = win.get_screen_width() / 2;
let height = win.get_screen_height();
draw.draw_rectangle(width, 0, 5, height, Color::WHITE);
Or you could just clone your instance:或者你可以克隆你的实例:
let (mut win, thread) = raylib::init().size(800, 600).title("Demo").build();
draw.draw_rectangle(win.clone().get_screen_width() / 2, 0, 5, win.clone().get_screen_height(), Color::WHITE);
Hope this help (and works ^^')希望这有帮助(并且有效^^')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.