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
Conversation
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.
Looks good! Thanks for doing this. Some notes inline 👍
tokio/src/fs/file.rs
Outdated
/// ``` | ||
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"); |
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.
Why is the downcast needed here?
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.
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
tokio/src/fs/file.rs
Outdated
/// # Ok(()) | ||
/// # } | ||
/// ``` | ||
pub async fn try_into_std(mut self) -> Result<sys::File, Self> { |
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.
This does not need to be async
.
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.
Right 👍
tokio/src/fs/file.rs
Outdated
@@ -394,6 +394,53 @@ impl File { | |||
Ok(File::from_std(std_file)) | |||
} | |||
|
|||
/// Destructures `File` into a [`std::fs::File`][std]. |
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.
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
Thanks! |
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