1 // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10 pub const DEFAULT_BUF_SIZE: usize = 8 * 1024;
13 #[allow(dead_code)] // not used on emscripten
15 use path::{Path, PathBuf};
17 use rand::{self, Rng};
20 pub struct TempDir(PathBuf);
23 pub fn join(&self, path: &str) -> PathBuf {
24 let TempDir(ref p) = *self;
28 pub fn path<'a>(&'a self) -> &'a Path {
29 let TempDir(ref p) = *self;
34 impl Drop for TempDir {
36 // Gee, seeing how we're testing the fs module I sure hope that we
37 // at least implement this correctly!
38 let TempDir(ref p) = *self;
39 fs::remove_dir_all(p).unwrap();
43 pub fn tmpdir() -> TempDir {
44 let p = env::temp_dir();
45 let mut r = rand::thread_rng();
46 let ret = p.join(&format!("rust-{}", r.next_u32()));
47 fs::create_dir(&ret).unwrap();