-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Merged by Bors] - Round out the untyped api s #7009
Conversation
/// | ||
/// In order to mark the value as changed, you need to call [`set_changed`](DetectChanges::set_changed) manually. | ||
#[inline] | ||
pub fn as_mut(&mut self) -> PtrMut<'_> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like how this silently bypasses change detection, it kind of defeats the point of having a change detection wrapper type. I see that MutUntyped::into_inner
already does this, but I think we should fix that too.
For consistency with Mut
, anything that might mutate the inner value should mark a change, and there should be an explicit bypass_change_detection
method for getting around that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, this change should go in the migration guide.
crates/bevy_ptr/src/lib.rs
Outdated
|
||
/// Gets a `PtrMut` from this with a smaller lifetime | ||
#[inline] | ||
pub fn shrink(&mut self) -> PtrMut<'_> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this method is chained together as part of a complex expression, I feel like it would be very unclear what this method is actually doing. reborrow
would be a better name IMO.
|
||
/// Gets an mutable reference from this | ||
#[inline] | ||
pub fn as_mut(&mut self) -> PtrMut<'_> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might make more sense to call this downgrade
, or something else to match PtrMut::promote
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
demote
is the natural counterpart.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On second thought, calling this demote
or downgrade
would only make sense if the method took self
by value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like to see:
- The doc / naming nits are addressed.
- A bypass_change_detection method.
Marking as breaking change as |
Co-authored-by: JoJoJet <21144246+JoJoJet@users.noreply.github.com>
bors r+ |
# 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.
Pull request successfully merged into main. Build succeeded:
|
# 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.
# 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.
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 enjoySolution
Add a couple methods to Ptr, PtrMut, and MutUntyped to allow for easy usage of these types in more complex scenarios.
Changelog
as_mut
andas_ref
methods toMutUntyped
.shrink
andas_ref
methods toPtrMut
.Migration Guide
MutUntyped::into_inner
now marks things as changed.