How to programmatically get the number of fields of a struct?

Are there any possible API like field_count() or is it only possible to get that via macros? There is no such built-in API that would allow you to get this information at runtime. Rust does not have runtime reflection (see this question for more information). But it is indeed possible via proc-macros! Note: proc-macros are … Read more

How to report errors in a procedural macro using the quote macro?

Apart from panicking, there are currently two ways to reports errors from a proc-macro: the unstable Diagnostic API and “the compile_error! trick”. Currently, the latter is mostly used because it works on stable. Let’s see how they both work. The compile_error! trick Since Rust 1.20, the compile_error! macro exists in the standard library. It takes … Read more

How do I see the expanded macro code that’s causing my compile error?

cargo rustc –profile=check — -Zunpretty=expanded, but a more concise alternative is the cargo-expand crate. It provides a Cargo subcommand cargo expand which prints the result of macro expansion. It also passes the expanded code through rustfmt which generally results in much more readable code than the default output from rustc. Install by running cargo install … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)