Today I played and found you can use cfg in function signatures.
fn main() {
#[cfg(not(feature = "use_generic"))]
confuged(42);
#[cfg(feature = "use_generic")]
confuged("fourty two");
}
fn confuged<#[cfg(feature = "use_generic")] T: Display>(
#[cfg(not(feature = "use_generic"))] var: u32,
#[cfg(feature = "use_generic")] var: T,
) {
println!("{}", var);
}
But not in the return part...
fn confuged<#[cfg(feature = "use_generic")] T: Display>(
#[cfg(not(feature = "use_generic"))] var: u32,
#[cfg(feature = "use_generic")] var: T,
) #[cfg(not(feature = "use_generic"))] -> ()
13 | ) #[cfg(not(feature = "use_generic"))] -> ()
| ^ expected one of `->`, `;`, `where`, or `{`
Part of my brain says "Do not do that". Impossible to read. But then I discovered you can also put comments and blank lines in the function signature and I wonder if I could make a small program just using cfg's in a function signature. is the combination of "all", "any", "not", and "cfg_attr" turing complete?
But of course reality and my day job might prevent that.