Skip to content
This repository was archived by the owner on Aug 20, 2021. It is now read-only.

Commit 8ff740f

Browse files
author
Paul Woolcock
committed
Add AsRef<Path> impl to TempDir
1 parent 1b77f7d commit 8ff740f

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,12 @@ impl TempDir {
305305
}
306306
}
307307

308+
impl AsRef<Path> for TempDir {
309+
fn as_ref(&self) -> &Path {
310+
self.path()
311+
}
312+
}
313+
308314
impl fmt::Debug for TempDir {
309315
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
310316
f.debug_struct("TempDir")

tests/smoke.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,16 @@ fn in_tmpdir<F>(f: F) where F: FnOnce() {
205205
f();
206206
}
207207

208+
pub fn pass_as_asref_path() {
209+
let tempdir = t!(TempDir::new("test"));
210+
takes_asref_path(&tempdir);
211+
212+
fn takes_asref_path<T: AsRef<Path>>(path: T) {
213+
let path = path.as_ref();
214+
assert!(path.exists());
215+
}
216+
}
217+
208218
#[test]
209219
fn main() {
210220
in_tmpdir(test_tempdir);
@@ -215,4 +225,5 @@ fn main() {
215225
in_tmpdir(recursive_mkdir_rel_2);
216226
in_tmpdir(test_remove_dir_all_ok);
217227
in_tmpdir(dont_double_panic);
228+
in_tmpdir(pass_as_asref_path);
218229
}

0 commit comments

Comments
 (0)