Gtk-rs: The huge and long awaited release is finally here
gtk-rs.org
gtk-rs.org
> Rust bindings for GTK+ 3, Cairo, GtkSourceView and other GLib-compatible libraries
I noticed there seems to be a webbrowser widget too, which I'll have to play with.
'Added PDF as a target Surface' that sounds very useful too!
I'm just wondering would it be possible to make the gtk widgets copyable, as wouldn't that mean you could remove the clone! macro calls, or am I mistaken there?
let button = Button::new_with_label("Click me!");
window.add(&button);
button.connect_clicked(|_| {
println!("Clicked!");
});
We just mutated the button (connect_clicked) while the window holds a reference to it. Isn't that disallowed in Rust? How do the GTK types interoperate with Rust ownership?You might want to say "hold on, how can this be safe?" The trick here is that there are runtime checks to make sure only one reference is used for mutation.
Oh, did you believe all checks needed to make Rust memory safe is done at compile time? Well that's too bad.
fn add<P: IsA<Widget>>(&self, widget: &P) {
unsafe {
ffi::gtk_container_add(self.to_glib_none().0, widget.to_glib_none().0);
}
}
Oh, did you believe that Rust always does checks to ensure memory safety? Well that's too bad.Unsafe blocks are for exactly those situations where the compiler can't prove safety at compile time, giving you an escape hatch to say "this really is safe, I know what I'm doing". There are some runtime-checked abstractions built on this, but they can't help you when interacting with non-Rust code.
[1] https://github.com/gtk-rs/gtk/blob/8949ac0304660f53e1fbe2850...
Here's one scenario that might invoke UB: create a top level widget, call destroy() [1] on it, then use the widget.
Does that invoke UB? If not, why not - how does Rust's ownership model interact with the GTK one?
[1] http://gtk-rs.org/docs/gtk/trait.WidgetExt.html#tymethod.des...
I thought that would settle the matter, but then I ran the unmodified code, and it generated essentially the same error messages. Filing a bug report right now.
The unsafe block is there because it does FFI, which hasn't actually been verified to be safe.
> The Rust compiler inherently doesn't trust ffi calls. That doesn't mean necessarily that the call is actually unsafe.
It's more that the possibility for UB now exists, than it definitely does.
Actually yes. You can write all the programs you want without runtime borrow checking, but it's inconvenient. Runtime borrow checking happens _only_ when you use cells.
> When disagreeing, please reply to the argument instead of calling names. "That is idiotic; 1 + 1 is 2, not 3" can be shortened to "1 + 1 is 2, not 3."
https://news.ycombinator.com/newsguidelines.html
You didn't call anyone names but the sarcasm and patronizing tone aren't necessary.
Is it an acronym for something, or is just someone on the team a closet Invader Zim fan? :)
GIR seems to be the XML format containing GObject introspection data.
For what it is worth, the equivelent haskell library (haskell-gi) is composed of two source code directories: GIR and CodeGen. [0]
[0] https://github.com/haskell-gi/haskell-gi/tree/master/lib/Dat...
It seems everything these days is going either Rust or Go.
Lots (most?) of things are simply just already built, keep on working and not going anywhere new.