-
Notifications
You must be signed in to change notification settings - Fork 63
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
Allow pin projection #76
Comments
Are there clear semantics for this? It seems that But maybe we could have manual methods for each? Something like: impl<L, R> Either<L, R> {
pub fn project(self: Pin<&mut Self>) -> Either<Pin<&mut L>, Pin<&mut R>>;
pub fn project_left(self: Pin<&mut Self>) -> Either<Pin<&mut L>, &mut R>
pub fn project_right(self: Pin<&mut Self>) -> Either<&mut L, Pin<&mut R>>;
} I'm not enough of a |
I have not thought about this actually. In our usage, we always have it on both because we implement traits on our Having said that, The question then is, should we even use the macro or implement it ourselves? I think that will require unsafe code. |
I notice that |
It does have a I just re-read the following section on pinning and I think it makes sense to include it here: https://doc.rust-lang.org/std/pin/index.html#projections-and-structural-pinning Esp. the last part:
Looking at the list of requirements for structural pinning, I think we can guarantee all of these? https://doc.rust-lang.org/std/pin/index.html#pinning-is-structural-for-field |
I see, and then it uses that for a But reading more about structural pinning, I think we should not do the left/right variations, because it would be unsafe to allow arbitrary combinations of these to be in use. The full |
Would it?
Also, going through the requirements list:
We could also expose an I wonder why the futures one is not public. I'll ask there! |
Yes, there is no sound way to provide multiple variations as a safe API (without Unpin bound).
The problem is that a field can be projected as a pinned field and then as an unpinned field. For example, it would allow for a future to be moved after polling.
|
The only bit I don't understand here is how you can call Also, assuming the entire |
You can reborrow self by using as_mut.
If there is a way to create a new let r = match either.project_left() {
Either::Right(r /* &mut R */) => std::mem::replace(r, R::new()),
_ => panic!(),
}; Otherwise, the same can be done by using let r = match either.project_left() {
Either::Right(r /* &mut Option<R> */) => r.take(),
_ => panic!(),
}; |
Got it, thank you for explaining in detail :) I conclude that exposing a |
It seems like a good idea to mimic the stable
Hmm, but it would be ok to have that proposed |
Not that I am aware but I agree that we should use std naming.
I think it is a better tradeoff in terms of API surface and orthogonality to only provide |
I agree that
Yeah, it needs
If |
Not sure whether this is in scope for this library but in
rust-libp2p
, we have a customEither
type because we need pin projection.Would you accept a PR for a feature-flagged pin projection implementation using the
pin-project
library?The text was updated successfully, but these errors were encountered: