Crate manifest_dir_macros[][src]

Manifest Dir Macros

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_stem!("src/lib.rs"));
println!(get_extension!("src/lib.rs"));
println!(get_parent!("src/lib.rs"));

#[cfg(feature = "mime_guess")]
println!(mime_guess!("src/lib.rs"));

// The `tuple` feature allows these macros to support inputting nested literal string tuples, which is useful when you want to use these macros inside a `macro_rules!` 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")));
}

Macros

absolute_path

Allows input a absolute path. Checks and returns the absolute path.

directory_absolute_path

Allows input a absolute path. Checks whether it is a directory and returns the absolute path.

directory_path

Allows input an absolute path, or a relative path. If a relative path is input, it will be relative to the CARGO_MANIFEST_DIR (a directory where your Cargo.toml located). Returns an absolute path, and it must be an existing directory.

directory_relative_path

Allows input a relative path. It will be relative to the CARGO_MANIFEST_DIR (a directory where your Cargo.toml located). Returns an absolute path, and it must be a directory.

exist_absolute_path

Allows input a absolute path. Checks whether it exists and returns the absolute path.

exist_path

Allows input an absolute path, or a relative path. (multiple components are supported) If a relative path is input, it will be relative to the CARGO_MANIFEST_DIR (a directory where your Cargo.toml located). Returns an absolute path, and it must exist.

exist_relative_path

Allows input a relative path. It will be relative to the CARGO_MANIFEST_DIR (a directory where your Cargo.toml located). Returns an absolute path, and it must exist.

file_absolute_path

Allows input a absolute path. Checks whether it is a file and returns the absolute path.

file_path

Allows input an absolute path, or a relative path. If a relative path is input, it will be relative to the CARGO_MANIFEST_DIR (a directory where your Cargo.toml located). Returns an absolute path, and it must be an existing file.

file_relative_path

Allows input a relative path. It will be relative to the CARGO_MANIFEST_DIR (a directory where your Cargo.toml located). Returns an absolute path, and it must be a file.

get_extension

Gets the file stem for other purposes. If there is no file extension, a compile error will be shown.

get_file_name

Gets the file name for other purposes. If there is no file name, a compile error will be shown.

get_file_stem

Gets the file stem for other purposes. If there is no file stem, a compile error will be shown.

get_parent

Gets the parent for other purposes. If there is no parent, a compile error will be shown.

not_directory_absolute_path

Allows input a absolute path. Checks whether it is not a directory and returns the absolute path.

not_directory_path

Allows input an absolute path, or a relative path. If a relative path is input, it will be relative to the CARGO_MANIFEST_DIR (a directory where your Cargo.toml located). Returns an absolute path, and it must not be an existing directory.

not_directory_relative_path

Allows input a relative path. It will be relative to the CARGO_MANIFEST_DIR (a directory where your Cargo.toml located). Returns an absolute path, and it must not be a directory.

path

Allows input an absolute path, or a relative path. If a relative path is input, it will be relative to the CARGO_MANIFEST_DIR (a directory where your Cargo.toml located). Returns an absolute path.

relative_path

Allows input a relative path. It will be relative to the CARGO_MANIFEST_DIR (a directory where your Cargo.toml located). Returns an absolute path.