]> git.lizzy.rs Git - rust.git/blob - src/libstd/sys_common/io.rs
Add `<*const T>::align_offset` and use it in `memchr`
[rust.git] / src / libstd / sys_common / io.rs
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.
4 //
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;
11
12 #[cfg(test)]
13 #[allow(dead_code)] // not used on emscripten
14 pub mod test {
15     use path::{Path, PathBuf};
16     use env;
17     use rand::{self, Rng};
18     use fs;
19
20     pub struct TempDir(PathBuf);
21
22     impl TempDir {
23         pub fn join(&self, path: &str) -> PathBuf {
24             let TempDir(ref p) = *self;
25             p.join(path)
26         }
27
28         pub fn path<'a>(&'a self) -> &'a Path {
29             let TempDir(ref p) = *self;
30             p
31         }
32     }
33
34     impl Drop for TempDir {
35         fn drop(&mut self) {
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();
40         }
41     }
42
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();
48         TempDir(ret)
49     }
50 }