I noticed some weird behavior today and couldn't find any documentation on how it works. It seems that format_args! and include_str!can actually work together to do compile-time validation of file inputs. Like so:
let html = format_args!(include_str!("./index.html"), title="test");
Both of these are compiler builtins so their sources aren't easily accessible. However, in neither of their documentation did I see any mention of this behavior. Contrast this with a proc/decl macro that tries to parse the inners as a LitStr/literal:
macro_rules! parse_args {
($a:literal) => {};
}
fn test() {
let nodes = parse_args!(include_str!("./htmlexample.html"));
}
with error:
|
12 | macro_rules! parse_args {
| ----------------------- when calling this macro
...
17 | let nodes = parse_args!(include_str!("./htmlexample.html"));
| ^^^^^^^^^^^ no rules expected this token in macro call
Is there any documentation for this behavior? Is there any way for macro developers to also leverage this mechanic for parse a str literal returned by include_str!?
I noticed some weird behavior today and couldn't find any documentation on how it works. It seems that
format_args!andinclude_str!can actually work together to do compile-time validation of file inputs. Like so:Both of these are compiler builtins so their sources aren't easily accessible. However, in neither of their documentation did I see any mention of this behavior. Contrast this with a proc/decl macro that tries to parse the inners as a LitStr/literal:
with error:
Is there any documentation for this behavior? Is there any way for macro developers to also leverage this mechanic for parse a str literal returned by
include_str!?