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

tokio::fs::File doesn't expose into_std() in 0.2 #1852

Closed
bartlomieju opened this issue Nov 28, 2019 · 3 comments · Fixed by #1856
Closed

tokio::fs::File doesn't expose into_std() in 0.2 #1852

bartlomieju opened this issue Nov 28, 2019 · 3 comments · Fixed by #1856

Comments

@bartlomieju
Copy link
Contributor

bartlomieju commented Nov 28, 2019

Version

tokio 0.2

Description

In tokio 0.1 one could get underlying std::fs::File instance from tokio::fs::File like so:

OpenOptions::new().open().and_then(move |tokio_file| {
  let std_file = tokio_file.into_std();
});

Unfortunately I did not find this method in tokio 0.2 which is very desirable - eg. I want to start new Command with file as stdout/stderr for that command. Command.stdout() requires Into<Stdio> which is implemented for std::fs::File but not tokio::fs::File.

EDIT:
As I see that design of tokio::fs::File changed it's not really useful to destructure the file. Something like async fn try_clone_std() -> std::fs::File would be fine 👍

@bartlomieju bartlomieju changed the title tokio::fs::File doesn't expose into_std() tokio::fs::File doesn't expose into_std() in 0.2 Nov 28, 2019
@carllerche
Copy link
Member

what about async fn into_std?

@bartlomieju
Copy link
Contributor Author

what about async fn into_std?

pub async fn into_std(&self) -> io::Result<sys::File> {
    let std = self.std.clone();
    let std_file = asyncify(move || std.try_clone()).await?;
    Ok(std_file)
}

@carllerche something along those lines? I'll be happy to open a PR

@carllerche
Copy link
Member

You would not need a clone. You would wait until the background operation is complete, then downcast then use Arc::try_unwrap to get the inner file.

You could also have a try_into_std(self) -> Result<sys::File, Self> that does the Arc::try_unwrap directly.

carllerche pushed a commit that referenced this issue Nov 29, 2019
In version 0.1 there was File::into_std method that destructured
tokio_fs::File into std::fs:File. That method was lacking in
version 0.2.

Fixes: #1852
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 a pull request may close this issue.

2 participants