Closed PudgeKim closed 1 year ago
I'm afraid there is no other way. I've been trying to find a way but I think the core of the issue is impl Get<Out=&'a Area>
and it can't be changed.
Usually with shared references the compiler can bend the lifetime but I don't think it can in this case.
There is in theory a way to make it work: having a function to go from &ViewMut
to View
. This way you could change impl Get
to View
.
But I'm not sure if this safe, none of the std types have it. Tokio has something close but it takes the ViewMut
by value.
I created a post on the forum asking if the function would be safe https://users.rust-lang.org/t/rwlockwriteguard-as-rwlockreadguard/94298.
Ok so I have not one but two ways to make it work.
ViewMut::as_view
to get a View
and use it to call inner_func
.impl Get<Out=&'a Area> + Copy
use &SparseSet<Area>
. I added an impl Get for &SparseSet
and will work for both View
and ViewMut
, you might have to add a &
or two.
I know It's not a shipyard related issue but I need some help.. Please understand the code below looks weird. The original code is quite long so I needed to summarize.
As you see, I have recursive function and this function calls other function which needs
impl Get<Out=...>
. But this code cannot be compiled. Here's the error message.I can compile this code when I change the code as below.
Is there anyway to compile this code without adding one more lifetime in
inner_func
? (Ifinner_func
has more parameters, I need to add many lifetime and I think it doesn't seem good.) What's the best and general way to fix this code?