include_optional


Note: This currently only works on nightly Rust. This crate depends on proc_macro::SourceFile::path(), which is not yet stabilized (additionally, there is a dependency on the unstable function std::path::Path::try_exists, however, this dependency could probably be removed without too much hassle).

If you are able to somehow avoid this dependency, pull requests are welcome!


This crate allows you to optionally include a file as a Option. This crate supports the complete include_X! macro family (include_bytes!, include! and include_str!).

Installation

Add this to your Cargo.toml: lang-toml [dependencies] include_optional = "1.0"

Example

This includes some metadata from a file, falling back to default metadata if the file is missing: ```rust use includeoptional::includestr_optional;

fn main() { let metadata: &'static str = includestroptional!("./metadatafiles/fileexists.txt" ).unwrap_or("default metadata string"); //... } ```