简体   繁体   English

不能将 `win` 借为不可变的,因为它也被借为可变的

[英]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.

相关问题 不能借用不可变的因为它也被借用为可变的 - cannot borrow as immutable because it is also borrowed as mutable 不能借用为不可变的,因为它也借用为可变的 - Cannot borrow as immutable because it also borrowed as mutable 不能借用 `...` 作为可变的,因为它也被借用为不可变的 - cannot borrow `…` as mutable because it is also borrowed as immutable 不能借用为可变的,因为它也被借用为不可变的 - Cannot borrow as mutable because it is also borrowed as immutable 借用检查器:不能借为不可变的,因为它也借为可变的 - Borrow Checker: Cannot borrow as immutable because it is also borrowed as mutable 不能将 X 作为不可变借用,因为它在可变闭包中也作为可变借用 - Cannot borrow X as immutable because it is also borrowed as mutable in a mutable closure 不能作为不可变借用,因为它在函数参数中也作为可变借用 - Cannot borrow as immutable because it is also borrowed as mutable in function arguments 不能将`* request`借用为可变因为它也被借用为不可变的 - cannot borrow `*request` as mutable because it is also borrowed as immutable 错误:不能借用......作为不可变的,因为它也被借为可变的 - error: cannot borrow … as immutable because it is also borrowed as mutable “不能将 `*arr` 作为不可变借用,因为它也作为可变借用”在函数调用中 - "Cannot borrow `*arr` as immutable because it is also borrowed as mutable" in a function call
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM