Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

1. Use a binding to a library or write your own. Gtk bindings are probably the most mature option, but there are some exciting in-progress ones.

2. Yes. One is even provided in the standard library, if that suits your needs. However, most people don’t use linked lists because other data structures are near-universally better.

3. Rust doesn’t have classes, but you can do something similar. The name is the “newtype pattern.”



Yeah, you can do newtypes (or just defining new types), in addition to Structs, Enums, and Traits.

For those who don't know, Traits are like a sort of "class interface" that can be automatically applied to things that have implementations for those traits, and conversion between, once that code is pulled in scope via `use`.

Rust doesn't have classes or inheritance, instead, it has more powerful tools, ones that aren't as limited.


Why is this being downvoted? Am I wrong about something? If so, please tell me, I'm still learning.

Ah. Maybe it's because I explained stuff that's basically newtypes using language that might make it seem they're different? Ugh. HN comments always make me so neurotic. But the content is usually more interesting than dev.to. I just wish they'd get rid of the downvote feature.


For what it's worth, I'm mildly experienced in Rust and your comment looks pretty much correct.

I'm recovering from a headache (and a little ketted out) so I might be missing something too, but in the spirit of trying to explain confusing downvotes, here's the only two potential nitpicks I can see:

  1. newtypes are not really 'in addition' to structs, enums, etc. they are a particular type of struct with a fancy name.   
  2. Calling composition less powerful than inheritance could be seen as subjective and debatable. I mostly like composition over inheritance, but Rust for example has problems with up-casting of trait objects (https://github.com/rust-lang/rfcs/issues/2765) that inheritance/vtable based languages (e.g. C++) do not have.
So it's not a bad comment, and I suspect you mostly just got piled on due to human error/bias. Or maybe some poor soul got confused and thought you were trying to explain Rust to the poster above you (who may not need much explaining).

Don't take it personally, you seem to have a good grasp of the language. Please keep on learning :)


Thanks! And of course not. I was just trying to support Steve's point, or expand on it a bit.

That was a thoughtful response, though, and I'm grateful.




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

Search: