-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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::options()
assoc function to mimic std
#5869
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.
Other than a few doc-nits, looks good to me.
tokio/src/fs/file.rs
Outdated
@@ -199,6 +195,37 @@ impl File { | |||
Ok(File::from_std(std_file)) | |||
} | |||
|
|||
/// Returns a new OpenOptions object. |
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.
/// Returns a new OpenOptions object. | |
/// Returns a new [`OpenOptions`] object. |
tokio/src/fs/file.rs
Outdated
@@ -199,6 +195,37 @@ impl File { | |||
Ok(File::from_std(std_file)) | |||
} | |||
|
|||
/// Returns a new OpenOptions object. | |||
/// | |||
/// This function returns a new OpenOptions object that you can use to |
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 function returns a new OpenOptions object that you can use to | |
/// This function returns a new `OpenOptions` object that you can use to |
tokio/src/fs/file.rs
Outdated
/// | ||
/// # async fn dox() -> std::io::Result<()> { | ||
/// let mut f = File::options().append(true).open("example.log").await?; | ||
/// f.write_all(b"new line").await?; |
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.
If we're appending a line, then we should write a newline.
/// f.write_all(b"new line").await?; | |
/// f.write_all(b"new line\n").await?; |
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.
My bad, it was writeln!()
in 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.
Thanks! LGTM.
I've found myself
std::fs::Files::options()
function really convenient and I accidentally typed it in tokio project. Hey, it would be an easy PR chance, right?Code is copied from std with minor modifications, including docs explaining its motivation.