3 ms·
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 i
by cryptoquick 6y ago
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.
- cryptoquick 6y agoWhy 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.
- loves_mangoes 6y agoFor 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 :)
- cryptoquick 6y agoThanks! 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.
- deleted 6y ago[deleted]