[Merged by Bors] - some cleanup for bevy_ptr#4668
Closed
jakobhellermann wants to merge 3 commits intobevyengine:mainfrom
Closed
[Merged by Bors] - some cleanup for bevy_ptr#4668jakobhellermann wants to merge 3 commits intobevyengine:mainfrom
bevy_ptr#4668jakobhellermann wants to merge 3 commits intobevyengine:mainfrom
Conversation
TheRawMeatball
approved these changes
May 5, 2022
BoxyUwU
approved these changes
May 5, 2022
BoxyUwU
reviewed
May 5, 2022
| #[inline] | ||
| #[allow(clippy::wrong_self_convention)] | ||
| pub unsafe fn as_ptr(self) -> *mut u8 { | ||
| pub fn as_ptr(self) -> *mut u8 { |
Member
There was a problem hiding this comment.
it probably doesnt matter but idk if we want to be consistent here or not 😅
Contributor
Author
There was a problem hiding this comment.
It's not needed here because Ptr: Copy so I kept it as is but it could also be &self for consistency. I don't have a strong opinion here.
james7132
approved these changes
May 5, 2022
Member
|
Ping @cart for an |
alice-i-cecile
approved these changes
May 5, 2022
Member
|
bors r+ |
bors bot
pushed a commit
that referenced
this pull request
May 6, 2022
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 rust-lang/rust#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)`
Contributor
bevy_ptrbevy_ptr
robtfm
pushed a commit
to robtfm/bevy
that referenced
this pull request
May 10, 2022
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 rust-lang/rust#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)`
exjam
pushed a commit
to exjam/bevy
that referenced
this pull request
May 22, 2022
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 rust-lang/rust#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)`
ItsDoot
pushed a commit
to ItsDoot/bevy
that referenced
this pull request
Feb 1, 2023
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 rust-lang/rust#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)`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PtrMut::as_ptr(self)andOwnedPtr::as_ptr(self)to take&self, otherwise printing the pointer will prevent doing anything else afterwardsas_ptrmethods safe. There's nothing unsafe about obtaining a pointer, these kinds of methods are safe in std as well str::as_ptr, Rc::as_ptroffset/addtobyte_offset/byte_add. The unprefixed methods in std add in increments ofstd::mem::size_of::<T>, not in bytes. There's a PR for rust to add these byte_ methods Add convenience byte offset/check align functions to pointers rust-lang/rust#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)