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 File::into_std and File::try_into_std methods #1856

Merged
merged 1 commit into from Nov 29, 2019
Merged

fs: add File::into_std and File::try_into_std methods #1856

merged 1 commit into from Nov 29, 2019

Conversation

bartlomieju
Copy link
Contributor

Motivation

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

Copy link
Member

@carllerche carllerche left a comment

Choose a reason for hiding this comment

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

Looks good! Thanks for doing this. Some notes inline 👍

/// ```
pub async fn into_std(mut self) -> sys::File {
self.complete_inflight().await;
let std_file = Arc::downcast::<sys::File>(self.std).expect("Arc::downcast failed");
Copy link
Member

Choose a reason for hiding this comment

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

Why is the downcast needed here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

TBH I took your suggestion from the issue. I guess I can directly Arc::try_unwrap(std_file).expect("Arc::try_unwrap failed") after awaiting to complete inflight operations

/// # Ok(())
/// # }
/// ```
pub async fn try_into_std(mut self) -> Result<sys::File, Self> {
Copy link
Member

Choose a reason for hiding this comment

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

This does not need to be async.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right 👍

@@ -394,6 +394,53 @@ impl File {
Ok(File::from_std(std_file))
}

/// Destructures `File` into a [`std::fs::File`][std].
Copy link
Member

Choose a reason for hiding this comment

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

Would you be able to add a short paragraph under this explaining that the function is async to allow for any in-flight operations to complete and to use try_into_std to attempt the conversion immediately.

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
@carllerche carllerche merged commit 4261ab6 into tokio-rs:master Nov 29, 2019
@carllerche
Copy link
Member

Thanks!

@bartlomieju bartlomieju deleted the fs_file_into_std branch November 29, 2019 08:57
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.

tokio::fs::File doesn't expose into_std() in 0.2
2 participants