Closed PudgeKim closed 1 year ago
You can't take a UniqueView
and UniqueViewMut
of the same component at the same time. The is also the case for View
/ViewMut
.
The error suggests to not borrow the shared view (UniqueView
/View
) since you can read from an exclusive view.
Should I split it to four custom view? or Is there other nice way to do?
It depends on what you are trying to do.
Yes, even if you split it in two you would still have access to both at the same time and it's not possible. It's the main rule of the borrow checker.
If you try with u32
for example:
fn borrow(immutable: &u32, mutable: &mut u32) {}
let mut i = 0;
borrow(&i, &mut i);
you'll get this error:
cannot borrow `i` as mutable because it is also borrowed as immutable
Shipyard moves the borrow check to runtime but the same rules apply.
The split MyView
/MyViewMut
makes sense to me but why do you want to get both at the same time?
MyViewMut
should be able to do everything MyView
can do and more.
I deleted the post by mistake. yeah I need to change all View to ViewMut. thank you.
I created some custom view which takes
EntitiesViewMut
,UniqueView
,UniqueViewMut
,View
andViewMut
. so it's ViewBundle.I got an error below.
Multiple views of the same storage including an exclusive borrow, consider removing the shared borrow.
Should I split it to four custom view? or Is there other nice way to do?