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

Add NamedTempFile<F>, Builder::{make,make_in}, and NamedTempFile::from_parts #177

Merged
merged 4 commits into from
Apr 10, 2022

Conversation

jasonwhite
Copy link
Contributor

@jasonwhite jasonwhite commented Apr 8, 2022

There are two main parts to this PR. Unfortunately GitHub doesn't really have the ability to make PRs depend on each other. Let me know if you want this split up into separate PRs.

Fixes #175

NamedTempFile<F = File>

This adds a generic parameter to NamedTempFile. This enables using it with non-File types, such as:

  • std::os::unix::net::UnixListener,
  • tokio::net::UnixListener, or
  • tokio::fs::File

This should be a backwards compatible change. To do this, some File-specific stuff is only implemented for NamedTempFile<File>.

Builder::{make,make_in}

This enables the user to leverage the file-path building part of the library while providing their own custom file creation callback. This is useful for creating UNIX domain sockets.

It was mentioned in #175 to provide a helper for creating sockets, but since UNIX domain sockets are only on UNIX, I believe it would be the only platform-dependent function. Thus, I held off on making that change. Happy to reconsider this though.

Note that NamedTempFile::from_parts was added to implement Builder::make_in. This could be made a private function, but it seems useful in the public API as well.

@jasonwhite jasonwhite changed the title Make NamedTempFile more generic Add NamedTempFile<F>, Builder::{make,make_in}, and NamedTempFile::from_parts Apr 9, 2022
@jasonwhite jasonwhite marked this pull request as ready for review April 9, 2022 00:07
src/file/mod.rs Outdated Show resolved Hide resolved
Copy link
Owner

@Stebalien Stebalien left a comment

Choose a reason for hiding this comment

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

Some small nits, otherwise LGTM.

src/file/mod.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
tests/namedtempfile.rs Show resolved Hide resolved
This enables using it with non-File types, like a `UnixListener`.

This should be a backwards compatible change.
This enables the user to do more generic temporary file path creation,
such as creating a temporary UNIX domain socket or creating a temporary
`tokio::fs::File` (without using `tokio::fs::File::from_std`).
@jasonwhite
Copy link
Contributor Author

jasonwhite commented Apr 9, 2022

Thanks for the review! All review comments should be addressed. Let me know if there's anything else.

Edit: FYI, I also ran cargo fmt and updated the changelog.

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.

Support for temporary UNIX domain sockets
2 participants