1 unstable release

0.1.0 Apr 18, 2019

#5 in #organization

Used in directree


126 lines


A macro for expressing a directory tree at compile time.

An example

The directree macro can be used to express a file hierarchy like so:

use directree::directree;

mod paths {
    directree! {
        foo: "dir" {
            bar: "file.toml",

            // Note that an empty {} is allowed, but does nothing other than
            // visually distinguish whether it's supposed to be a file or a
            // directory.
            baz: "subdir" {},

directree turns this DSL into a series of modules and functions with the same hierarchy:

mod paths {
    fn foo() -> &'static std::path::Path {
    mod foo {
        fn bar() -> &'static std::path::Path {
        fn baz() -> &'static std::path::Path {

This can then be used to obtain specified files and directories in normal code:

let foo_dir = std::fs::OpenOptions::new()

let bar_file = std::fs::OpenOptions::new()

But why?

It's useful to be able to specify all files and directories your software needs access to in one place. Doing so provides your software with a single source of truth on what things are named on disk and where they are stored. Using this project will also allow the compiler to catch typos in module and function names instead of having to manually verify directories written by hand.


~41K SLoC