- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 17
Support custom Drop implementation #25
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
Conversation
6f36e08    to
    24ea784      
    Compare
  
    9ba5c56    to
    c69d44f      
    Compare
  
    | pin_project! { | ||
| pub struct S { | ||
| #[pin] | ||
| field: u8, | ||
| } | ||
| impl PinnedDrop for S { | ||
| fn drop(self: Pin<&mut Self>) { | ||
| self.__drop_inner(); | ||
| } | ||
| } | ||
| } | 
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.
Hmm..., I expected this to fail to compile, but it seems that it actually compiles.
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.
(resolved by using normal arg  instead self)
ffcdb4a    to
    2c4f45d      
    Compare
  
    36fdbb2    to
    9bd49ab      
    Compare
  
    95ecba3    to
    8161149      
    Compare
  
    49b091d    to
    8fbccc7      
    Compare
  
    | What's t he current state of this? | 
| The implementation is basically done except for this fixme and lack of documentation. The latter is probably easy, as we can just copy the description of this PR and pin-project's docs. Line 1204 in 30f66dd 
 | 
| bors r+ Well, documentation is not a blocker. Filed #61 to follow-up. | 
25: Support custom Drop implementation r=taiki-e a=taiki-e
```rust
use pin_project_lite::pin_project;
pin_project! {
    pub struct Struct<'a> {
        was_dropped: &'a mut bool,
        #[pin]
        field: u8,
    }
    impl PinnedDrop for Struct<'_> {
        fn drop(this: Pin<&mut Self>) { // <----- NOTE: this is not `self`
            **this.project().was_dropped = true;
        }
    }
}
fn main() {
    let mut was_dropped = false;
    drop(Struct { was_dropped: &mut was_dropped, field: 42 });
    assert!(was_dropped);
}
```
It's clear how to pass options(=arguments in `#[pin_project]`), and we don't have to think about how to pass options.
So, this is easiest to implement compared to other options.
For all other options, we have to start by deciding how to pass the options, which can be a hard task, whether simple or complex to implement.
Co-authored-by: Taiki Endo <[email protected]>
    | Canceled. | 
| bors r+ | 
| Build succeeded: | 
| Released in v0.2.7 | 
It's clear how to pass options(=arguments in
#[pin_project]), and we don't have to think about how to pass options.So, this is easiest to implement compared to other options.
For all other options, we have to start by deciding how to pass the options, which can be a hard task, whether simple or complex to implement.