-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Add examples for std::pin::Pin new() and into_inner() methods #104195
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @Mark-Simulacrum (or someone else) soon. Please see the contribution instructions for more information. |
Hey! It looks like you've submitted a new PR for the library teams! If this PR contains changes to any Examples of
|
library/core/src/pin.rs
Outdated
/// use std::pin::Pin; | ||
/// | ||
/// let val: u8 = 5; | ||
/// // Wrap the value in a pin to make sure it doesn't move |
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 isn't quite accurate. Since Target: Unpin
, the value can move again.
/// // Wrap the value in a pin to make sure it doesn't move | |
/// // The value doesn't care about being moved, so we can pin it just fine |
I don't like my wording here a lot, feel free to improve it, but something like this is better.
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 guess that a better option is Pin the value in memory to make sure that during the program lifecycle the value is not moved in another memory address
?
…into documentation-104107
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.
Some others comment regarding the PR are:
- Use the
Fixes https://github.com/rust-lang/rust/issues/104107
to make sure that the PR is linked with the issue - Try to squash the commit in a single one if the commit are simple the same things
Co-authored-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
library/core/src/pin.rs
Outdated
/// | ||
/// let val: u8 = 5; | ||
/// // We can pin the value, since it doesn't care about being moved | ||
/// let pinned: Pin<&u8> = Pin::new(&val); |
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.
It seems like an example of Pin with a shared reference is probably not the best bet -- most users will not want that. I think we should demonstrate with a &mut reference at least.
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.
let mut val: u8 = 5;
let mut pinned: Pin<&mut u8> = Pin::new(&mut val);
println!("{}", pinned); // 5
pinned.as_mut().set(10);
println!("{}", pinned); // 10
Would this work?
@rustbot author |
cc/ @rust-lang/wg-async I ran out of time to review this before going out of office. Can others take a look at this, perhaps during the next triage? I want to make sure we don't let this slip. Thanks! |
@rustbot label -S-waiting-on-author +S-waiting-on-review |
r? @yoshuawuyts |
@bors r+ |
Add examples for std::pin::Pin new() and into_inner() methods Fixes rust-lang#104107
https://rustc-dev-guide.rust-lang.org/git.html#no-merge-policy, commits should be rebased/squashed |
@bors r- |
@ch-iv could you rebase and squash the commit in a single one? so we can get this in soon! |
…=eholk docs: improve pin docs Override rust-lang#104195 with a full cleanup of the git history, now it should be ready to be merged. r? `@eholk` `@rustbot` label +A-async-await
…=eholk docs: improve pin docs Override rust-lang#104195 with a full cleanup of the git history, now it should be ready to be merged. r? ``@eholk`` ``@rustbot`` label +A-async-await
docs: improve pin docs Override rust-lang/rust#104195 with a full cleanup of the git history, now it should be ready to be merged. r? ``@eholk`` ``@rustbot`` label +A-async-await
Fixes #104107