Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compile time check if file at path exists? like include_str!(..)

I like how include_str!(..) works. Is there a macro that simply checks if the file exists instead of loading the contents of the file?

Use case? I want to make sure that all the file paths that are valid before I release it, to prevent runtime error.

So the file path has to be checked even if the macro isn't called during runtime.

OR should I be using tests here?

like image 440
Bron Avatar asked Nov 28 '25 12:11

Bron


1 Answers

This will do for now.

#[macro_export]
macro_rules! find_file{
    ($arg1:literal) => {
        {
            //opportunity for improvement
            let _ = include_bytes!($arg1);
            let r = $arg1;
            r
        }
    };
}

@PitaJ thanks

like image 70
Bron Avatar answered Nov 30 '25 04:11

Bron