Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for coercing bevy mutable references to values #643

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

MalekiRe
Copy link

@MalekiRe MalekiRe commented Oct 7, 2023

No description provided.

@udoprog
Copy link
Collaborator

udoprog commented Oct 7, 2023

I fiddled a bit with the patch, so please take it for a spin. Instead of pulling in UnsafeToValue2 and calling unsafe_to_value you'll have to switch to using rune::bevy_support::anyobj_from_bevy_mut.

Some notes:

I like keeping everything in bevy_related. I also noted that AnyObjVTable is supposed to be public (but wasn't). So I've made it public.

AFAICT, using a trait UnsafeToValue2 doesn't net you much. You just have to pull it into scope anyways. So I've opted to just provide a function.

The reason we can't implement UnsafeToValue (which would be nice) is because of the ToValue blanket implementation. I'd definitely consider the blanket implementation because it would enable this which makes calling into rune better for you. This shouldn't be a big deal, since Any is mostly derived so we can easily just implement this as appropriate. Once this is implementable it can essentially just use the function.

MutUntyped has lifetimes, so MutUntyped is the same as MutUntyped<'static>. Coercing to 'static is a bit sketchy, but without bevy exposing raw APIs (which I think they should to enable sound uses like this) we don't have much of a choice.

@udoprog udoprog changed the title added bevy specific features and add mut_ptr stuff Add support for coercing bevy mutable references to values Oct 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants