Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/magiclen/manifest-dir-macros
This crate provides function-like macros to check or operate paths relative to CARGO_MANIFEST_DIR at compile time.
https://github.com/magiclen/manifest-dir-macros
rust
Last synced: 28 days ago
JSON representation
This crate provides function-like macros to check or operate paths relative to CARGO_MANIFEST_DIR at compile time.
- Host: GitHub
- URL: https://github.com/magiclen/manifest-dir-macros
- Owner: magiclen
- License: mit
- Created: 2021-05-05T01:39:09.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2023-09-09T05:36:00.000Z (over 1 year ago)
- Last Synced: 2024-05-03T04:47:49.700Z (8 months ago)
- Topics: rust
- Language: Rust
- Homepage:
- Size: 58.6 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Manifest Dir Macros
====================[![CI](https://github.com/magiclen/manifest-dir-macros/actions/workflows/ci.yml/badge.svg)](https://github.com/magiclen/manifest-dir-macros/actions/workflows/ci.yml)
This crate provides function-like macros to check or operate paths relative to **CARGO_MANIFEST_DIR** at compile time.
## Examples
```rust
#[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](LICENSE)