1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
//! # PathBuf builder
//! Make building PathBuf easier and cleaner.

/// Shorten PathBuf building code.
///
/// # Examples
///
/// ```
/// use std::path::Path;
/// assert_eq!(path_buf!["/foo", "bar"].as_path(), Path::new("/foo/bar"));
/// ```
#[macro_export]
macro_rules! path_buf {
    ($($e: expr),*) => {{
        use std::path::PathBuf;
        let mut pb = PathBuf::new();
        $(
            pb.push($e);
        )*
        pb
    }}
}

#[cfg(test)]
mod tests {
    #[test]
    fn test1() {
        use std::path::Path;
        assert_eq!(path_buf!["/foo", "bar"].as_path(), Path::new("/foo/bar"));
    }
}