-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Add close
method to File
#59567
Comments
We could even add this method to |
Having three methods with the same declaration and name seems like bad design to me... Suggestions? |
Perhaps we should have a
|
However, this has major problems with recursive dropping. Like what if two different fields have different Perhaps we should have a
Then have |
And what would be the benefice of having such error handling ? Error in closing file are generally logical error like trying to close a file not open (and this should happen in Rust). Also close a file doesn't guarantee that the file has been write too. So, I don't think we need this feature. But I agree that not be able to handle this error is lame. |
This is not true. According to the close man page, close can give you an error if the IO didn't finish successfully.
Yet the operating system can give us an error and we choose to ignore it. |
See also: #24413 (reverse-duplicate of this bug) rust-lang/rfcs#770 (closed RFC about this topic) Some external discussions about the topic: |
@tbu- could != must
https://linux.die.net/man/2/close If any one need to be sure data is write, use sync_all is way better |
Yes. IMO, this doesn't mean we should throw away the error the operating system gives us. |
As @dtolnay says in #32255 (comment), this change would require an RFC. Please pursue this over at https://github.com/rust-lang/rfcs. Thanks! |
Another use-case: https://users.rust-lang.org/t/close-file-before-drop/70071 |
Currently, as far as I know, there is no way to close a file and handle errors with closing it. It would be useful to add a method to
File
that allows us to handle any potential errors instead of them being ignored.The text was updated successfully, but these errors were encountered: