lexi

i like breaking computers

  • it/its, #[deprecated] she/her
  • ./a.out

i like rust, nix, linux, infosec, webdev and i shitpost a lot. ctf player and so-called "security researcher". aroace, agender, nb, nd, disabled, &, ΘΔ :3 🏳️‍⚧️ 🟨⬜️🟪⬛️

picrew: #1322863


honestly, there is one thing about rust that is really annoying.

objects. (ew.)

if you have tried to use the gtk crate, you've probably seen this before:

// A GLib Subclass
#[glib::object_subclass]
impl ObjectSubclass for CustomButton {
const NAME: &'static str = "MyGtkAppCustomButton";
type Type = super::CustomButton;
type ParentType = gtk::Button;
}

and. uh. what on earth is that. can we not do that, please.

rust generally doesn't do object-oriented programming, which is super nice, but if you have something like GLib that is just so inherently OOPish that you have to do that you either have to rewrite the whole thing in rust (which isnt bad, but time-consuming) or just live with that thing. in general, having something like this built-in for OOP compatibility would be super nice:

struct Button {
label: String,
clicked: bool
}

#[extend]
struct CountingButton {
extends: Button,
number: i32
}
// would expand to:
// struct CountingButton {
// label: String,
// clicked: bool,
// number: i32
// }

impl CountingButton {
fn new(n: i32) {
CountingButton {
label: n.to_string(),
clicked: false,
number: n
}
}
fn check_clicked(&self) {
if self.clicked {
self.number += 1;
self.label = self.number.to_string();
}
}
}

something along the lines of that, or just using an extends property would be so much nicer. a real extension system that can be manually imported into rust would make development with existing software so much better. i might read into proc macros myself if i have time and implement a good OOP system for rust because working with OOP is as bad in rust as in C++ etc. i can just write C++ gui code if i want a bad experience lol


You must log in to comment.

in reply to @lexi's post:

by the way, if you're wondering how i did the syntax highlighting: JetBrains IDEs copy code as both plain text and HTML, and if you want that HTML source do this:

  • open up a JetBrains IDE
  • copy the code
  • go to data:text/html,<body contenteditable> in your browser
  • paste the code
  • open inspect element
  • select the <pre> tag
  • press CTRL-C
  • paste that html code here