#relative-path #directory #root #compile-time #project #cargo-manifest-dir

macro no-std manifest-dir-macros

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

15 releases

0.1.18 Sep 9, 2023
0.1.17 Apr 18, 2023
0.1.16 May 8, 2022
0.1.14 Mar 17, 2022
0.1.11 May 5, 2021

#2484 in Rust patterns

Download history 2774/week @ 2024-03-14 2038/week @ 2024-03-21 1816/week @ 2024-03-28 1619/week @ 2024-04-04 1646/week @ 2024-04-11 1741/week @ 2024-04-18 1590/week @ 2024-04-25 1332/week @ 2024-05-02 986/week @ 2024-05-09 1925/week @ 2024-05-16 2070/week @ 2024-05-23 1409/week @ 2024-05-30 1452/week @ 2024-06-06 1535/week @ 2024-06-13 1719/week @ 2024-06-20 1417/week @ 2024-06-27

6,329 downloads per month
Used in 28 crates (12 directly)

MIT license

28KB
511 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 lets 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.3–0.9MB
~20K SLoC