Skip to content
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

fs: add into_std implementation for File #1773

Closed
wants to merge 1 commit into from

Conversation

afinch7
Copy link
Contributor

@afinch7 afinch7 commented Nov 14, 2019

This should be a fairly simple one. Just reintroducing a function that got left behind at some point.

/// # }
/// ```
pub fn into_std(self) -> sys::File {
Arc::try_unwrap(self.std).unwrap()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah... yeah, this can panic if there is an in-flight job working with the file. I'm not sure what to do about this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if it would be an alternative for a method, but I was thinking about adding a TryFrom implementation like this:

use std::convert::TryFrom;

impl TryFrom<File> for sys::File {
    type Error = File;

    fn try_from(f: File) -> Result<Self, Self::Error> {
        let File {
            std,
            state,
            last_write_err,
        } = f;
        Arc::try_unwrap(std).map_err(|std| File {
            std,
            state,
            last_write_err,
        })
    }
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could do that, but the caller has no way to know if the file is at a point where it can succeed.

We could make it an async fn...

Copy link
Contributor Author

@afinch7 afinch7 Nov 17, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't really want to make this async, but we could just 'try_clone' the std file and return that.

let std = self.std.clone();
asyncify(move || std.try_clone())

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a TryFrom might work...

@carllerche
Copy link
Member

Thanks for the work. I'm sorry it didn't pan out. I'm going to close this as it is not possible to add IntoRaw* implementations. I did add AsRaw* implementations here: #1827

@carllerche carllerche closed this Nov 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants