#macro

pathbuf

A macro to conveniently build PathBufs

3 releases (breaking)

0.3.1 Jan 13, 2023
0.3.0 Jan 13, 2023
0.2.0 Jan 13, 2023
0.1.0 Jan 13, 2023

#929 in Rust patterns

Download history 81/week @ 2023-08-15 69/week @ 2023-08-22 119/week @ 2023-08-29 134/week @ 2023-09-05 124/week @ 2023-09-12 84/week @ 2023-09-19 96/week @ 2023-09-26 246/week @ 2023-10-03 69/week @ 2023-10-10 38/week @ 2023-10-17 81/week @ 2023-10-24 79/week @ 2023-10-31 68/week @ 2023-11-07 39/week @ 2023-11-14 44/week @ 2023-11-21 52/week @ 2023-11-28

227 downloads per month
Used in mdbook-readme-summary

Apache-2.0

6KB

pathbuf

pathbuf is a simple crate which provides the pathbuf macro to conveniently construct the Rust PathBuf type.

Example

use pathbuf::pathbuf;
use std::path::PathBuf;

fn main() {
	let p = pathbuf!["hello", "filename.txt"];

	let expected = {
		let mut temp = PathBuf::new();
		temp.push("hello");
		temp.push("filename.txt");
		temp
	};

	assert_eq!(p, expected);
}

License

pathbuf is licensed under the Apache 2.0 license, and is itself a reproduction of the hc_pathbuf crate found in Hipcheck, pulled out into its own distinct crate for reuse.


lib.rs:

pathbuf provides a single macro, pathbuf!, which gives a vec!-like syntax for constructing PathBufs.

Example

#
fn do_something(dir: &Path) {
    let file_name = pathbuf![dir, "filename.txt"];

    if file_name.exists() {
        // do something...
    }
}

No runtime deps