chisel_common/macros/
files.rs

1/// Macro for some relative file shennigans
2#[macro_export]
3macro_rules! relative_file {
4    ($f : expr) => {{
5        let base = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
6        base.join($f)
7    }};
8}
9
10/// Instantiate a file relative to the cargo manifest directory
11#[macro_export]
12macro_rules! file_from_relative_path {
13    ($f : expr) => {
14        let path = env::current_dir().unwrap().join($f);
15        File::open(path).unwrap();
16    };
17}
18
19/// Take some bytes and create a [BufRead]
20#[macro_export]
21macro_rules! reader_from_bytes {
22    ($b : expr) => {{
23        let buffer: &[u8] = $b.as_bytes();
24        BufReader::new(buffer)
25    }};
26}
27
28/// Grab all the lines from a file relative to the current directory
29#[macro_export]
30macro_rules! lines_from_relative_file {
31    ($f : expr) => {{
32        let path = env::current_dir().unwrap().join($f);
33        let f = File::open(path).unwrap();
34        BufReader::new(f).lines()
35    }};
36}
37
38/// Create a reader based on a relative file
39#[macro_export]
40macro_rules! reader_from_relative_file {
41    ($f : expr) => {{
42        let path = env::current_dir().unwrap().join($f);
43        let f = File::open(path).unwrap();
44        BufReader::new(f)
45    }};
46}