-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
expand the documentation on the Unpin
trait
#53104
Merged
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
038ce65
expand the documentation on the `Unpin` trait
nivkner 6845dc4
correct explenation on the usage of NonNull
nivkner 9b7d710
fix link to PinBox
nivkner 87bbd2e
fix style issues in doc comment
nivkner 68e766a
remove general pinning information from Unpin trait
nivkner 03530fa
add example for moving out of pointer
nivkner 6ae915b
clarify use of Unpin and pinning types
nivkner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -609,16 +609,27 @@ unsafe impl<'a, T: ?Sized> Freeze for &'a mut T {} | |
/// this trait cannot prevent types from moving by itself. | ||
/// | ||
/// Instead it can be used to prevent moves through the type system, | ||
/// by controlling the behavior of special pointers types like [`PinMut`], | ||
/// which "pin" the type in place by wrapping it in a type which can only be dereferenced immutably. | ||
/// by controlling the behavior of special pointer types like [`PinMut`], | ||
/// which "pin" the type in place by not allowing it to be moved out via mutable references. | ||
/// | ||
/// Implementing this trait lifts the restrictions of pinning off a type, | ||
/// which then allows it to move out of said pointers with functions such as [`swap`]. | ||
/// which then allows it to move out of said pointers, with functions such as [`replace`]. | ||
/// | ||
/// So this, for example, can only be done on types implementing `Unpin`: | ||
/// | ||
/// ```rust | ||
/// #![feature(pin)] | ||
/// use std::mem::{PinMut, replace}; | ||
/// | ||
/// let mut string = "this".to_string(); | ||
/// let mut pinned_string = PinMut::new(&mut string); | ||
/// replace(&mut *pinned_string, "other".to_string()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd add a comment in the code here saying that the |
||
/// ``` | ||
/// | ||
/// This trait is automatically implemented for almost every type. | ||
/// | ||
/// [`PinMut`]: ../mem/struct.PinMut.html | ||
/// [`swap`]: ../mem/fn.swap.html | ||
/// [`replace`]: ../mem/fn.replace.html | ||
#[unstable(feature = "pin", issue = "49150")] | ||
pub auto trait Unpin {} | ||
|
||
|
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.
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 remove the "via" part or make it a "for example" -- after all,
PinMut
prevents all ways to move something out. It doesn't just prevent moving out via&mut
.