-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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] - Add safe constructors for untyped pointers Ptr
and PtrMut
#6539
Conversation
This looks reasonable to me, but I've added |
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.
This looks correct, but yes, I want verification from one of the pointer wizards.
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.
Looks good to me.
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.
Generally LGTM. Some small nits.
bors r+ |
# Objective Currently, `Ptr` and `PtrMut` can only be constructed via unsafe code. This means that downgrading a reference to an untyped pointer is very cumbersome, despite being a very simple operation. ## Solution Define conversions for easily and safely constructing untyped pointers. This is the non-owned counterpart to `OwningPtr::make`. Before: ```rust let ptr = unsafe { PtrMut::new(NonNull::from(&mut value).cast()) }; ``` After: ```rust let ptr = PtrMut::from(&mut value); ``` Co-authored-by: Carter Anderson <mcanders1@gmail.com>
Pull request successfully merged into main. Build succeeded:
|
Ptr
and PtrMut
Ptr
and PtrMut
…gine#6539) # Objective Currently, `Ptr` and `PtrMut` can only be constructed via unsafe code. This means that downgrading a reference to an untyped pointer is very cumbersome, despite being a very simple operation. ## Solution Define conversions for easily and safely constructing untyped pointers. This is the non-owned counterpart to `OwningPtr::make`. Before: ```rust let ptr = unsafe { PtrMut::new(NonNull::from(&mut value).cast()) }; ``` After: ```rust let ptr = PtrMut::from(&mut value); ``` Co-authored-by: Carter Anderson <mcanders1@gmail.com>
…gine#6539) # Objective Currently, `Ptr` and `PtrMut` can only be constructed via unsafe code. This means that downgrading a reference to an untyped pointer is very cumbersome, despite being a very simple operation. ## Solution Define conversions for easily and safely constructing untyped pointers. This is the non-owned counterpart to `OwningPtr::make`. Before: ```rust let ptr = unsafe { PtrMut::new(NonNull::from(&mut value).cast()) }; ``` After: ```rust let ptr = PtrMut::from(&mut value); ``` Co-authored-by: Carter Anderson <mcanders1@gmail.com>
…gine#6539) # Objective Currently, `Ptr` and `PtrMut` can only be constructed via unsafe code. This means that downgrading a reference to an untyped pointer is very cumbersome, despite being a very simple operation. ## Solution Define conversions for easily and safely constructing untyped pointers. This is the non-owned counterpart to `OwningPtr::make`. Before: ```rust let ptr = unsafe { PtrMut::new(NonNull::from(&mut value).cast()) }; ``` After: ```rust let ptr = PtrMut::from(&mut value); ``` Co-authored-by: Carter Anderson <mcanders1@gmail.com>
Objective
Currently,
Ptr
andPtrMut
can only be constructed via unsafe code. This means that downgrading a reference to an untyped pointer is very cumbersome, despite being a very simple operation.Solution
Define conversions for easily and safely constructing untyped pointers. This is the non-owned counterpart to
OwningPtr::make
.Before:
After: