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::options() assoc function to mimic std #5869

Merged
merged 3 commits into from
Jul 16, 2023

Conversation

HyeonuPark
Copy link
Contributor

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.

@Darksonn Darksonn added A-tokio Area: The main tokio crate M-fs Module: tokio/fs labels Jul 16, 2023
Copy link
Contributor

@Darksonn Darksonn left a 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.

@@ -199,6 +195,37 @@ impl File {
Ok(File::from_std(std_file))
}

/// Returns a new OpenOptions object.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/// Returns a new OpenOptions object.
/// Returns a new [`OpenOptions`] object.

@@ -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
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/// This function returns a new OpenOptions object that you can use to
/// This function returns a new `OpenOptions` object that you can use to

///
/// # async fn dox() -> std::io::Result<()> {
/// let mut f = File::options().append(true).open("example.log").await?;
/// f.write_all(b"new line").await?;
Copy link
Contributor

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.

Suggested change
/// f.write_all(b"new line").await?;
/// f.write_all(b"new line\n").await?;

Copy link
Contributor Author

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.

Copy link
Contributor

@Darksonn Darksonn left a comment

Choose a reason for hiding this comment

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

Thanks! LGTM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio Area: The main tokio crate M-fs Module: tokio/fs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants