I was watching a talk about Idris 2 and it was
mentioned that you can implement a type safe printf
using dependent types (around 10 minutes in).
And I was wondering if you could do something like that in rust. And you can, ish!
error[E0308]: mismatched types
--> src/main.rs:145:13
|
145 | let x = printf::<"that's a %s %s, aged %u!">("cute", "dog");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `"%s%s"`, found `"%s%s%u"`
|
= note: expected constant `"%s%s"`
found constant `"%s%s%u"`
That’s done with no macros, just a lot of const
code of dubious quality.