[rust-dev] Generics?

Graydon Hoare graydon at mozilla.com
Fri Apr 5 09:24:58 PDT 2013


On 13-04-04 03:01 PM, Jeaye Wilkerson wrote:
> 
> On Apr 4, 2013, at 2:55 PM, Steve Klabnik wrote:
> 
>> You should probably be using macros where you were using C++ templates, no?
> 
> 
> Ahh, you're right. I see now that macros can essentially be C++ templates; plug in a type and see if it compiles! An epiphanic moment, indeed.

Not quite. It won't do SFINAE or backtracking. If the syntax fits, it'll
expand, regardless of types. If the types don't fit, typechecking will
fail-fail and the macro won't try some other pattern. So it's not quite
the same as templates. As patrick said, it's more like
templates-with-concepts (and without backtracking).

I _believe_ the type system remains non-turing-complete. That's always
been a goal for me anyway!

(The macro system is turing complete, but apparently this is pretty much
the norm in macro systems. It's not type-aware, which is what you were
after.)

-Graydon



More information about the Rust-dev mailing list