Skip to content

EliasHolzmann/include_optional

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

include_optional

MSRV: 1.88


Note: With default feature flags, this crate has a known bug in regards to proc-macro caching. If an included file does not exist and a macro from this crate returns None, this result is cached forever. The macro isn't reevaluated when the file is added later. A fix for this is currently not possible in Stable Rust.

If you are running Nightly Rust, you can enable the nightly feature. With this, this crate makes use of the unstable track_path feature that is necessary in order to fix this. Otherwise, you will have to call cargo clean after adding an included file to force reevaluation.


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:

[dependencies]
include_optional = "1.0"

Example

This includes some metadata from a file, falling back to default metadata if the file is missing:

use include_optional::include_str_optional;
let metadata:  &'static str = include_str_optional!("./metadata_files/file_exists.txt" ).unwrap_or("default metadata string");

About

Option-returning versions of include_X macros

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Packages

No packages published

Languages