# repo_path
Access paths in your repository, with compile-time checks.
This is useful in particular when you're writing your CI code in Rust, e.g. via the [cargo-xtask pattern](https://github.com/matklad/cargo-xtask).
```rust
use repo_path::repo_path;
let readme = repo_path!("README.md");
let assets_dir = repo_path!("assets/");
let repo_root = repo_path!(); //equivalent to repo_path!(".")
```
The macro checks whether the path exists and constructs a `PathBuf` containing an absolute path.
If the path does not exist, the compiler will error during compilation:
```rust,compile_fail
use repo_path::repo_path;
let non_existent = repo_path!("non/existent/path.txt");
```
This allows you to move files around without having to worry that a reference silently breaks, similar to the way [`std::include_str!()`](https://doc.rust-lang.org/stable/std/macro.include_str.html) works.
## Custom base path
If you'd like to paths to be relative to a different directory in your repository, you can generate your own macro with `custom_base_path_macro!()`:
```rust
use repo_path::custom_base_path_macro;
custom_base_path_macro!(assets_path, "assets/"); //generates the assets_path!() macro
let file = assets_path!("file.txt");
```
This is useful when you need to reference a particular sub-directory often or in case your Rust code is placed in a sub-directory of the repository.
## How it works
During compilation, the macro looks for the `.git` directory to determine the root of your repository.
Then it joins the path you specified to the root (or your custom base path) and checks if the resulting path exists and lies within your repository.
The path of your repository root is cached during compilation, so that you can use `repo_path!()` many times without a significant compile-time burden.
## Usage in a library
Because the macro fetches the path during compilation, you cannot use it in libraries that want to access your user's repository (it will return paths for your own repository).
For that purpose, use the [repo_path_lib](https://crates.io/crates/repo_path_lib) crate instead.
## Changelog
See the changelog here: <https://codeberg.org/trem/repo_path/src/branch/main/CHANGELOG.md>