-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Tracking issue for Pin APIs (RFC 2349) #49150
Comments
I now notice that stack pinning is not part of the RFC, @withoutboats are you planning on releasing a crate for this, or should I just copy the example code into my crate that needs it? |
@Nemo157 You should copy it and report your experience! The unresolved question about leaking One thing I'll note is that the stack pinning was not sufficient for things like |
My current usage is pretty trivial, a single-threaded executor running a single |
Just tried to experiment with the API. Looks like the following (suggested by RFC) definition of trait Future {
type Item;
type Error;
fn poll(self: Pin<Self>, cx: &mut task::Context) -> Poll<Self::Item, Self::Error>;
} |
Nevermind. Found a note about a plan to make |
Could you elaborate on that? |
@RalfJung You need |
@cramertj That sounds like a restriction of the |
@RalfJung Yes, that's correct. However, |
Given a |
@RalfJung No-- methods like |
It might be the case that we could get this to work with |
@cramertj I did not suggest to call |
@RalfJung Oh, I see. Yes, using a method to manually reborrow could work. |
I'll try and remember to post an example of some of the stuff I'm doing with |
Here's the full example of what I'm using for reading: pub trait Read {
type Error;
fn poll_read(
self: Pin<Self>,
cx: &mut task::Context,
buf: &mut [u8],
) -> Poll<usize, Self::Error>;
}
pub fn read_exact<'a, 'b: 'a, R: Read + 'a>(
mut this: Pin<'a, R>,
buf: &'b mut [u8],
) -> impl StableFuture<Item = (), Error = Error<R::Error>>
+ Captures<'a>
+ Captures<'b> {
async_block_pinned! {
let mut position = 0;
while position < buf.len() {
let amount = await!(poll_fn(|cx| {
Pin::borrow(&mut this).poll_read(cx, &mut buf[position..])
}))?;
position += amount;
if amount == 0 {
Err(Error::UnexpectedEof)?;
}
}
Ok(())
}
} This is slightly annoying as you have to pass instances through everywhere as #[async]
fn foo<'a, R>(source: Pin<'a, R>) -> Result<!, Error> where R: Read + 'a {
loop {
let mut buffer = [0; 8];
await!(read_exact(Pin::borrow(&mut source), &mut buffer[..]));
// do something with buffer
}
} |
I just had a thought that I could |
Concern: It seems likely that we want most types in libstd to implement Will this solve itself if we make sure to implement |
Yes, it seems like the same situation as |
A new question just occurred to me: When are |
@RalfJung |
Well, just like some types are |
I've had to learn the Pin API due to my work with Futures, and I have a question.
Taken together, that allows for moving a pinned value with entirely safe code. Is this intended? What is the rationale for why this is safe to do? |
It looks like you have What you likely want is |
EDIT: no longer accurate
|
@tmandry Correct me if I'm wrong, but Note that |
Oh, the rules must have changed since I last used these. Sorry for the confusion. |
@tmandry Yes, the changes were very recent. Since things are still in flux, it's hard to keep up with all the changes. |
The comment by @tikue is correct. You need to remember that pins only pin one level of indirection down. |
@tikue @tmandry @withoutboats Thanks for the answers! It was very helpful. |
So what are the states of the two concerns now? ( |
@crlf0710 see the stabilization proposal. |
Expand std::pin module docs and rename std::pin::Pinned to PhantomPinned cc #49150, #55766 r? @withoutboats
@withoutboats Seems done? Shall we close? |
Ok I apologise if this is not the place to post this, but I have been thinking about the
Here is a sketchy PoC of the idea: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=9aae40afe732babeafef9dab3d7525a8 Anyways, imho this should remain in |
@danielhenrymantilla I don't see how that solves the problem of compatibility with existing generic drop impls, like |
You're right it requires another thing: That should make it become
|
This has a huge effect on the overall API design, and was discussed extensively as part of the |
Yep, huge cost short term since all existing libraries would need to update to be But it is a fair concern (I did not know that it had been raised previously; thank you for pointing it out, @RalfJung ), and I guess that the short term practical drawbacks do out-weight the little safety gain of a |
Has there been any discussion on |
|
Tracking issue for rust-lang/rfcs#2349
Blocking stabilization:
Unresolved questions:
!Unpin
data?Edit: Summary comment: #49150 (comment) (in the hidden-by-default part)
The text was updated successfully, but these errors were encountered: