# Objective - The function `BlobVec::replace_unchecked` has informal use of safety comments. - This function does strange things with `OwningPtr` in order to get around the borrow checker. ## Solution - Put safety comments in front of each unsafe operation. Describe the specific invariants of each operation and how they apply here. - Added a guard type `OnDrop`, which is used to simplify ownership transfer in case of a panic. --- ## Changelog + Added the guard type `bevy_utils::OnDrop`. + Added conversions from `Ptr`, `PtrMut`, and `OwningPtr` to `NonNull<u8>`. |
||
|---|---|---|
| .. | ||
| 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.