Michael-F-Bryan / include_dir

The logical evolution of the include_str macro for embedding a directory tree into your binary.
https://michael-f-bryan.github.io/include_dir
MIT License
319 stars 36 forks source link

When including a directory the directory name is not saved #93

Closed czocher closed 1 year ago

czocher commented 1 year ago

Example test:

use include_dir::{include_dir, Dir};

static DIRECTORY: Dir = include_dir!("$CARGO_MANIFEST_DIR/some_directory");

#[cfg(test)]
mod tests {
    use std::ffi::OsStr;
    use super::*;

    #[test]
    fn test() {
        assert_eq!(
            Some(OsStr::new("some_directory")),
            DIRECTORY.path().file_name()
        );
    }
}

The above test fails due to:

left: `Some("some_directory")`,
right: `None`

I would expect the root directory name to be saved. Is this a bug or a design choice? Would you accept a PR to change this behavior?

Michael-F-Bryan commented 1 year ago

This is working as intended.

I don't think we'd gain anything by making the DIRECTORY.path() from static DIRECTORY: Dir = include_dir!("$CARGO_MANIFEST_DIR/some_directory") always evaluate to "some_directory". It'd force every lookup to be prepended with some_directory/, which seems a bit unnecessary.