mirror of
https://github.com/bevyengine/bevy
synced 2024-11-26 22:50:19 +00:00
0ddaa7e83a
# Objective Bevy uses custom `Ptr` types so the rust borrow checker can help ensure lifetimes are correct, even when types aren't known. However, these types don't benefit from the automatic lifetime coercion regular rust references enjoy ## Solution Add a couple methods to Ptr, PtrMut, and MutUntyped to allow for easy usage of these types in more complex scenarios. ## Changelog - Added `as_mut` and `as_ref` methods to `MutUntyped`. - Added `shrink` and `as_ref` methods to `PtrMut`. ## Migration Guide - `MutUntyped::into_inner` now marks things as changed. |
||
---|---|---|
.. | ||
src | ||
Cargo.toml | ||
README.md |
bevy_ptr
The bevy_ptr
crate provides low-level abstractions for working with pointers in a more safe way than using rust's raw pointers.
Rust has lifetimed and typed references (&'a T
), unlifetimed and typed references (*const T
), but no lifetimed but untyped references.
bevy_ptr
adds them, called Ptr<'a>
, PtrMut<'a>
and OwningPtr<'a>
.
These types are lifetime-checked so can never lead to problems like use-after-frees and must always point to valid data.