Hacker News new | past | comments | ask | show | jobs | submit login

I like Rust a lot, but I strongly agree. “Advanced” Rust becomes as inscrutable as C++ template crap.

I really wish Rust had a way to define “template style” generic functions rather than “trait style”. Some things simply can not be done gracefully with trait spaghetti.




> I really wish Rust had a way to define “template style”

It has! It's called proc macro [1]. I'm only half joking.

[1] It can generate anything, errors generally suck ass in it as much in C++ templates and it feels similarly brittle.

> “Advanced” Rust becomes as inscrutable as C++ template crap.

I think people are abusing traits a bit too much. They are very nifty and often compile to very optimized code.

That said this trait is not an example of such abuse. Having a trait to help with overloading is the most benign form of trait use.

Solution to grandparent's problem is called rust analyzer. It will show you what methods are usable on your variable.


Rust macro hell is even worse than Rust trait spaghetti. I regularly refuse to use crates because they’re macro based and there’s a no macro alternative.

But you’re not wrong :)


There's always a no-macro alternative: expanding the macro by hand.

What's macro spaghetti?


Certainly it's possible to generate meaningful error messages within proc macros. Most folks don't bother though.


I would assert it is actually worse than C++, because at least templates and constexpr execution still looks like plain C++, while macros in Rust, with two additional levels of syntax, add even more complexity.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: