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

Add try_include_dir for fallible directory inclusion #64

Closed jbr closed 2 years ago

jbr commented 2 years ago

Currently, include_dir::include_dir panics if the directory does not exist, which makes it difficult to use in library code that can't guarantee the existence of a particular root directory. include_dir::try_include_dir introduces a way to attempt to include a directory but compile in a Result::Err literal instead of the directory, allowing library code to use this in a macro and gracefully handle the scenario where the directory is missing.

Michael-F-Bryan commented 2 years ago

Can you give me a good example of where you might need this?

My opinion is that you should have access to all required directories at compile time, so if you are trying to embed a directory that doesn't exist it should be a compile error. There is no try_include_str!() macro in std, for instance.