]> git.lizzy.rs Git - rust.git/blob - src/libstd/sys_common/io.rs
Auto merge of #68037 - msizanoen1:riscv-ci, r=alexcrichton
[rust.git] / src / libstd / sys_common / io.rs
1 pub const DEFAULT_BUF_SIZE: usize = 8 * 1024;
2
3 #[cfg(test)]
4 #[allow(dead_code)] // not used on emscripten
5 pub mod test {
6     use crate::env;
7     use crate::fs;
8     use crate::path::{Path, PathBuf};
9     use rand::RngCore;
10
11     pub struct TempDir(PathBuf);
12
13     impl TempDir {
14         pub fn join(&self, path: &str) -> PathBuf {
15             let TempDir(ref p) = *self;
16             p.join(path)
17         }
18
19         pub fn path(&self) -> &Path {
20             let TempDir(ref p) = *self;
21             p
22         }
23     }
24
25     impl Drop for TempDir {
26         fn drop(&mut self) {
27             // Gee, seeing how we're testing the fs module I sure hope that we
28             // at least implement this correctly!
29             let TempDir(ref p) = *self;
30             fs::remove_dir_all(p).unwrap();
31         }
32     }
33
34     pub fn tmpdir() -> TempDir {
35         let p = env::temp_dir();
36         let mut r = rand::thread_rng();
37         let ret = p.join(&format!("rust-{}", r.next_u32()));
38         fs::create_dir(&ret).unwrap();
39         TempDir(ret)
40     }
41 }