Skip to content

Commit cbd1e97

Browse files
authored
feat: rename TempDir::into_path to TempDir::keep (#349)
This unifies the `TempDir`/`NamedTempFile` method names to help avoid confusion.
1 parent 4491d04 commit cbd1e97

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

src/dir/mod.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,13 @@ impl TempDir {
382382
self.path.as_ref()
383383
}
384384

385+
/// Deprecated alias for [`TempDir::keep`].
386+
#[must_use]
387+
#[deprecated = "use TempDir::keep()"]
388+
pub fn into_path(self) -> PathBuf {
389+
self.keep()
390+
}
391+
385392
/// Persist the temporary directory to disk, returning the [`PathBuf`] where it is located.
386393
///
387394
/// This consumes the [`TempDir`] without deleting directory on the filesystem, meaning that
@@ -400,14 +407,13 @@ impl TempDir {
400407
///
401408
/// // Persist the temporary directory to disk,
402409
/// // getting the path where it is.
403-
/// let tmp_path = tmp_dir.into_path();
410+
/// let tmp_path = tmp_dir.keep();
404411
///
405412
/// // Delete the temporary directory ourselves.
406413
/// fs::remove_dir_all(tmp_path)?;
407414
/// # Ok::<(), std::io::Error>(())
408415
/// ```
409-
#[must_use]
410-
pub fn into_path(self) -> PathBuf {
416+
pub fn keep(self) -> PathBuf {
411417
// Prevent the Drop impl from being called.
412418
let mut this = mem::ManuallyDrop::new(self);
413419

src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,8 @@ impl<'a, 'b> Builder<'a, 'b> {
469469
/// [`NamedTempFile`]/[`TempDir`]. When `keep` is set to `true`, this behavior is suppressed.
470470
///
471471
/// If you wish to keep a temporary file or directory after creating it, call
472-
/// [`NamedTempFile::keep`] or [`TempDir::into_path`] respectively.
472+
/// [`NamedTempFile::keep`] or [`TempDir::keep`] respectively to turn it into a regular
473+
/// file/path (respectively) that won't be automatically deleted.
473474
///
474475
/// # Examples
475476
///

tests/tempdir.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ fn test_rm_tempdir() {
8585
let path;
8686
{
8787
let tmp = TempDir::new().unwrap();
88-
path = tmp.into_path();
88+
path = tmp.keep();
8989
}
9090
assert!(path.exists());
9191
fs::remove_dir_all(&path).unwrap();
@@ -128,7 +128,7 @@ fn test_rm_tempdir_close() {
128128
let path;
129129
{
130130
let tmp = TempDir::new().unwrap();
131-
path = tmp.into_path();
131+
path = tmp.keep();
132132
}
133133
assert!(path.exists());
134134
fs::remove_dir_all(&path).unwrap();

0 commit comments

Comments
 (0)