bevy
bevy copied to clipboard
Add safe constructors for untyped pointers `Ptr` and `PtrMut`
Objective
Currently, Ptr and PtrMut can only be constructed via unsafe code. This means that downgrading a reference to an untyped pointer is very cumbersome, despite being a very simple operation.
Solution
Define conversions for easily and safely constructing untyped pointers. This is the non-owned counterpart to OwningPtr::make.
Before:
let ptr = unsafe { PtrMut::new(NonNull::from(&mut value).cast()) };
After:
let ptr = PtrMut::from(&mut value);
This looks reasonable to me, but I've added S-Controversial so it doesn't get merged before @TheRawMeatball has given their input.
bors r+
Pull request successfully merged into main.
Build succeeded:
- build-and-install-on-iOS
- build-android
- build (macos-latest)
- build (ubuntu-latest)
- build-wasm
- build (windows-latest)
- build-without-default-features (bevy)
- build-without-default-features (bevy_ecs)
- build-without-default-features (bevy_reflect)
- check-compiles
- check-doc
- check-missing-examples-in-docs
- ci
- markdownlint
- run-examples
- run-examples-on-wasm
- run-examples-on-windows-dx12