Stebalien / tempfile

Temporary file library for rust
http://stebalien.com/projects/tempfile-rs
Apache License 2.0
1.2k stars 120 forks source link

Allow to control suffix for NamedTempFile #264

Closed MaxG87 closed 1 year ago

MaxG87 commented 1 year ago

As described in #263 , for a test I write I need to create a temporary file that I pass on to a CLI under test. I need to choose the suffix of the file name.

I couldn't find how to do so using NamedTempFile directly. Instead, I had to use the Builder, which I found a bit cumbersome. Therefore, I wanted to ask whether it would be possible to add something like NamedTempFile::with_suffix(...) or even NamedTempFile::from_pattern.

The latter, from_pattern, would allow to use NamedTempFile a bit like Unix' mktemp, which I would find awesome.

Stebalien commented 1 year ago

First, I'd rather not parse templates/patterns.

In terms of with_suffix, I added support for with_prefix because it makes debugging much easier and specifying a prefix is very common. On the other hand, if you need this much control over the temporary file name, you're likely better served by using the Builder explicitly (really, it exists so that we don't have to create a bunch of one-off constructors).

Also see:

That's hardly perfect information, but it appears that prefix is much more common.

MaxG87 commented 1 year ago

This sounds a very reasonable. I will stick with the Builder then. Thank you very much.