#directory #project #root #cargo-manifest-dir

no-std manifest-dir-macros

This crate provides function-like macros to check or operate paths relative to CARGO_MANIFEST_DIR at compile time

10 releases

0.1.11 May 5, 2021
0.1.10 May 5, 2021

#271 in Rust patterns

Download history 486/week @ 2021-06-27 428/week @ 2021-07-04 619/week @ 2021-07-11 317/week @ 2021-07-18 420/week @ 2021-07-25 603/week @ 2021-08-01 762/week @ 2021-08-08 495/week @ 2021-08-15 357/week @ 2021-08-22 309/week @ 2021-08-29 423/week @ 2021-09-05 527/week @ 2021-09-12 813/week @ 2021-09-19 567/week @ 2021-09-26 508/week @ 2021-10-03 520/week @ 2021-10-10

283 downloads per month
Used in 17 crates (7 directly)

MIT license

28KB
551 lines

Manifest Dir Macros

CI

This crate provides function-like macros to check or operate paths relative to CARGO_MANIFEST_DIR at compile time.

Examples

#[macro_use] extern crate manifest_dir_macros;

println!(path!("Cargo.toml"));
println!(path!("src/lib.rs"));
println!(path!("src", "lib.rs"));
println!(path!("src", "lib.rs", "/bin"));
println!(path!("/usr"));

println!(exist_path!("Cargo.toml"));
println!(directory_path!("src"));
println!(not_directory_path!("Cargo.toml"));
println!(file_path!("Cargo.toml"));

println!(relative_path!("Cargo.toml"));
println!(directory_relative_path!("src"));
println!(not_directory_relative_path!("Cargo.toml"));
println!(file_relative_path!("Cargo.toml"));

println!(get_file_name!("src/lib.rs"));
println!(get_file_name!(default = "main.rs", "/"));
println!(get_file_stem!("src/lib.rs"));
println!(get_file_stem!(default = "lib", "/"));
println!(get_extension!("src/lib.rs"));
println!(get_extension!(default = "rs", "src/lib"));
println!(get_parent!("src/lib.rs"));
println!(get_parent!(default = "/home", "/"));

#[cfg(feature = "mime_guess")]
{
    println!(mime_guess!("src/lib.rs"));
    println!(mime_guess!(default = "application/octet-stream", "Cargo.lock"));
}

// The `tuple` feature let these macros above support to input nested literal string tuples, which is useful when you want to use these macros inside a `macro_rule!` macro and concatenate with other literal strings.
// `$x:expr` matchers can be used in these macros thus.
#[cfg(feature = "tuple")]
{
    println!(path!(("foo",)));
    println!(path!(("foo", "bar")));
    println!(path!("a", ("foo", "bar")));
    println!(path!(("foo", "bar"), "a"));
    println!(path!(("foo", "bar"), ("a", "b")));
    println!(path!(("foo", "bar", ("a", "b")), ("c", "d")));
}

Crates.io

https://crates.io/crates/manifest-dir-macros

Documentation

https://docs.rs/manifest-dir-macros

License

MIT

Dependencies

~0.4–0.8MB
~20K SLoC