Re:Implementing a Type-safe printf in Rust
by quietbritishjim on Friday August 14, 2020 @07:23AM
(#24156503)
The parent comment's point is just that variadic templates would make it easier to do the exact job talked about in this blog post. It sounds like you're objecting but you haven't quite said that outright. Are Rust macros less susceptible to the problem you're describing?
[ Parent
| on HN ]
Re:Implementing a Type-safe printf in Rust
by monadic2 on Friday August 14, 2020 @12:14PM
(#24159799)
Yea, traits make this much simpler to avoid. The problematic type would not match the trait, likely leading to much simpler communication of the error.
Re:Implementing a Type-safe printf in Rust
by quietbritishjim on Friday August 14, 2020 @02:25PM
(#24161437)
I'm not really convinced. In C++, you could start your hypothetical format function with static_assert(formatter<T>:: exists) or similar and get a very similar error message. (In C++ template terminology, a class like that is also called a trait, funnily enough, but that's just a convention rather than a language feature.) I think you could use C++ concepts to check add part of the function signature, but the functional difference would be very small. And none of these – including Rust traits – help you with compile time checking of format specifiers.