4 ms·
How do I do GUI in Rust? User interface dialogs. Can I do linked lists in Rust? Can I define classes such that: cInches in1, in2, in3; // basically a floa
by GnarfGnarf 6y ago
How do I do GUI in Rust? User interface dialogs.
Can I do linked lists in Rust?
Can I define classes such that:
cInches in1, in2, in3; // basically a float
cCm cm; // basically a float
in1 = in2 + in3; // OK
in1 == 2.f * in2; // OK
in1 = in2 / in3; // compilation error
cm = in1; // compilation error
void foo(cInches in);
foo(cm); // compilation error
- steveklabnik 6y ago1. 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.”
- cryptoquick 6y agoYeah, 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]
- Cyph0n 6y ago1. https://www.areweguiyet.com/ https://www.areweguiyet.com/ 2. https://doc.rust-lang.org/std/collections/struct.LinkedList.html https://doc.rust-lang.org/std/collections/struct.LinkedList.... 3. Example: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=961ebe6da81141b9a0c4c822d40816e8 https://play.rust-lang.org/?version=stable&mode=debug&editio...
- GnarfGnarf 6y agoWow! That's impressive. Did you just whip this up? :o) I've got 500KLOC C++/Qt running under Windows and macOS. I wonder if Qt have any plans.
- Cyph0n 6y agoYep! I enjoy using the language :) There is a crate called “cxx” that provides support for C++ interop in Rust: https://cxx.rs/ https://cxx.rs/
- monocasa 6y agoFully idiomatic GUIs are still an open problem in Rust, but I wrote a Win32 MDI application in Rust last week. It just makes you feel gross, but it's the same as other native code. Linked Lists are easy. _Doubly_ linked lists can't happen without Rc or unsafe, but that's fine. And yes you can create types for domain units, while controlling the combinations like that, and can go deeper in that sort of idea than C and C++.