-
-
Notifications
You must be signed in to change notification settings - Fork 1.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
refactor(lib): remove pin related unsafe code #2220
Conversation
match mem::replace(&mut me.state, State::Tmp) { | ||
State::NotReady(mut svc, req) => { | ||
me.state = State::Called(svc.call(req)); | ||
match me.state.as_mut().project_replace(State::Tmp) { |
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.
project_replace
is an optional method recently added.
It is equivalent to
Pin::set
, except that the unpinned fields are moved and returned, instead of being dropped in-place.fn project_replace(self: Pin<&mut Self>, other: Self) -> ProjectionOwned;The
ProjectionOwned
type is identical to theSelf
type, except that all pinned fields have been replaced by equivalentPhantomData
types.
src/service/oneshot.rs
Outdated
state: State<S, Req>, | ||
} | ||
|
||
#[pin_project(Replace, project = StateProj, project_replace = StateProjOwn)] |
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 is not ideal that we need to have both Replace
and project_replace = <name>
as project_replace = <name>
implies that a project_replace
method is generated.
I'll fix it soon.
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.
Do you mean I should wait to merge, or just some time 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.
Oh sorry, a fix for this was already merged, but I forgot to release a new version.
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.
Updated to use a new version pin-project which includes a fix for this. (402506d)
243: Allow `project_replace` argument to be used without `Replace` r=taiki-e a=taiki-e Currently, both `Replace` and `project_replace = <name>` arguments are required to name the return value of `project_replace()` method. ```rust #[pin_project(Replace, project_replace = EnumProjOwn)] enum Enum<T> { Variant(#[pin] T) } ``` It is not ideal that we need to have both `Replace` and `project_replace = <name>` as `project_replace = <name>` implies that a `project_replace` method is generated. This PR makes `project_replace` argument to use without `Replace` argument. ```diff - #[pin_project(Replace, project_replace = EnumProjOwn)] + #[pin_project(project_replace = EnumProjOwn)] enum Enum<T> { Variant(#[pin] T) } ``` Also, makes `project_replace` argument an alias for `Replace` so that it can be used without a value. ```rust #[pin_project(project_replace)] enum Enum<T> { Variant(#[pin] T) } ``` Related: rust-lang/futures-rs#2176 (comment) hyperium/hyper#2220 (comment) Co-authored-by: Taiki Endo <[email protected]>
No description provided.