bevy/crates/bevy_ptr
Jakob Hellermann d63b7e9568 some cleanup for bevy_ptr (#4668)
1. change `PtrMut::as_ptr(self)` and `OwnedPtr::as_ptr(self)` to take `&self`, otherwise printing the pointer will prevent doing anything else afterwards
2. make all `as_ptr` methods safe. There's nothing unsafe about obtaining a pointer, these kinds of methods are safe in std as well [str::as_ptr](https://doc.rust-lang.org/stable/std/primitive.str.html#method.as_ptr), [Rc::as_ptr](https://doc.rust-lang.org/stable/std/rc/struct.Rc.html#method.as_ptr)
3. rename `offset`/`add` to `byte_offset`/`byte_add`. The unprefixed methods in std add in increments of `std::mem::size_of::<T>`, not in bytes. There's a PR for rust to add these byte_ methods https://github.com/rust-lang/rust/pull/95643 and at the call site it makes it much more clear that you need to do `.byte_add(i * layout_size)` instead of `.add(i)`
2022-05-06 19:15:24 +00:00
..
src some cleanup for bevy_ptr (#4668) 2022-05-06 19:15:24 +00:00
Cargo.toml bevy_ptr standalone crate (#4653) 2022-05-04 19:16:10 +00:00
README.md bevy_ptr standalone crate (#4653) 2022-05-04 19:16:10 +00:00

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.