Crates.io | include_optional |
lib.rs | include_optional |
version | 1.0.1 |
source | src |
created_at | 2021-08-14 16:37:34.96969 |
updated_at | 2021-08-15 11:00:34.902676 |
description | Option-returning versions of include_X macros |
homepage | |
repository | https://github.com/EliasHolzmann/include_optional |
max_upload_size | |
id | 436602 |
size | 30,037 |
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!
).
Add this to your Cargo.toml
:
[dependencies]
include_optional = "1.0"
This includes some metadata from a file, falling back to default metadata if the file is missing:
use include_optional::include_str_optional;
fn main() {
let metadata: &'static str = include_str_optional!("./metadata_files/file_exists.txt" ).unwrap_or("default metadata string");
//...
}