
Gtk-rs: The huge and long awaited release is finally here - trextrex
http://gtk-rs.org/blog/2017/08/20/new-release.html
======
msla
From the homepage:

> Rust bindings for GTK+ 3, Cairo, GtkSourceView and other GLib-compatible
> libraries

[http://gtk-rs.org/](http://gtk-rs.org/)

------
anfractuosity
Congratulations, keep up the good work!

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?

------
ridiculous_fish
How does a pointer-soup toolkit like GTK work with Rust? For example, this
code:

    
    
        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?

~~~
nialv7
In Rust there is this concept called interior mutability. Which allows the
user to mutate something through a shared reference (&T).

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.

~~~
yorwba
Except this isn't guaranteed to be safe, because the implementation [1] just
calls GTK in an _unsafe_ block:

    
    
        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...](https://github.com/gtk-
rs/gtk/blob/8949ac0304660f53e1fbe28503a970d5d75bae91/src/auto/container.rs#L111)

~~~
alphaalpha101
So given that this isn't actually safe, you can presumably write some code
that has undefined behaviour using this library for us?

~~~
steveklabnik
unsafe{} means "hey compiler, you cannot verify but this is safe, but I have."
This code _should_ be safe to use, unless the human involved has messed
something up, in which case, it's a bug.

It's more that the _possibility_ for UB now exists, than it definitely does.

~~~
jononor
Maybe unsafe should be called assume_safe or presumably_safe or
maybe_unsafe... People easily understand it wrong

~~~
steveklabnik
We considered many things, but in the end, nothing is perfect.

------
Scarbutt
Is Gtk bundle into the final executable?

~~~
brunoqc
Each example binary is about 3-4 MB when built in release mode and they use
the gtk .so files.

~~~
jnbiche
So a static build is not possible?

~~~
snuxoll
Gtk+ is complex enough that statically linking libgtk3 isn't going to be
enough anyway, there's all sorts of extra resources GTK relies upon beyond the
.so that it's rather pointless to even try.

~~~
jnbiche
How then are people packaging gtk-rs for Windows? Any idea?

~~~
anfractuosity
I've just used WiX ([http://wixtoolset.org/](http://wixtoolset.org/)) to
bundle GTKs dlls together with my program. I've not investigated statically
linking GTK though.

------
josteink
Looking at the change log, I see they generate a lot of code with a custom
tool called "gir":

[https://github.com/gtk-rs/gir](https://github.com/gtk-rs/gir)

Is it an acronym for something, or is just someone on the team a closet
Invader Zim fan? :)

~~~
IronBacon
Without looking at the code, considering we are talking about GTK, I would
guess it's related to "GObject Introspection".

------
senatorobama
Can we come up with something other than GObject/GTK? :(. I want a cross
platform GUI that looks native.

------
gigatexal
Kudos to the collaborators.

It seems everything these days is going either Rust or Go.

~~~
kronos29296
It's just an echo chamber effect. People still use other languages for their
daily stuff. It's just that people want to write their hobby projects and new
small work stuff in go or rust. Would take some years for main stream adoption
that current popular and established languages enjoy. But rust and go have
momentum going for them.

