mirror of
https://github.com/bevyengine/bevy
synced 2024-11-26 14:40:19 +00:00
c1a4e29a1e
# Objective Since rust `1.76`, [`ptr::from_ref`](https://doc.rust-lang.org/stable/std/ptr/fn.from_ref.html) and [`ptr::from_mut`](https://doc.rust-lang.org/stable/std/ptr/fn.from_mut.html) are stable. This PR replaces code that use `as` casting by one of `ptr::from_ref`, `ptr::from_mut`, `cast_mut`, `cast_const`, or `cast` methods, which are less error-prone. ## Solution - Bump MSRV to `1.76.0` - Enables the following clippy lints: - [`ptr_as_ptr`](https://rust-lang.github.io/rust-clippy/master/index.html#/ptr_as_ptr) - [`ptr_cast_constness`](https://rust-lang.github.io/rust-clippy/master/index.html#/ptr_cast_constness) - [`ref_as_ptr`](https://rust-lang.github.io/rust-clippy/master/index.html#/ref_as_ptr) (I fix all warnings for this one, but it requires rust 1.77 to be enabled) - Fix the lints mentioned above |
||
---|---|---|
.. | ||
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.