11---
22layout : post
33author : GuillaumeGomez
4- title : Simplification and more everything
4+ title : Simplification and more of everything
55categories : [front, crates]
6- date : 2019-12-14 16 :00:00 +0000
6+ date : 2019-12-15 19 :00:00 +0000
77---
88
9- * Write intro here *
9+ Hello everyone, time for a new release!
10+
11+ This time, this is mostly about stabilization and simplification. It means that ` gtk-rs ` is now
12+ simpler to use and more complete than ever. Let's take a tour of what's new(er)!
13+
14+ ### Macro to make gtk-rs usage far simpler
15+
16+ A big productivity killer when using ` gtk-rs ` in the past was the requirement to pass cloned
17+ references to objects, or even worse, weak references into signal handler closures. This is still
18+ required but to make it more ergonomic, a new ` clone! ` macro is provided as part of ` glib ` .
19+
20+ See the [ documentation] ( https://docs.rs/glib/0.9.0/glib/macro.clone.html ) for various examples on
21+ how to use it. The big advantage of the macro is that you don't have to manually declare new local
22+ variables with a different name that are then moved into the closure, but simply have to provide the
23+ name of the variable you want to make available in the closure and whether it should be passed as a
24+ strong or weak reference. Inside the closure it can then be used as-is and for example upgrading any
25+ weak references manually is not necessary. In case of failure of upgrading a weak reference, an
26+ optional default return value for the closure can be provided or the closure can be configured to
27+ panic.
28+
29+ The macro works on any ` glib::Object ` as well as on any ` Arc ` and ` Rc ` .
30+
31+ As a side-note, it is important to know the difference between strong and weak references and not
32+ simply clone (strong reference) everything. By using strong references everywhere, many GTK
33+ applications (not only in Rust) currently create reference cycles and therefore have memory leaks.
34+ If, for example, you want to pass a reference to your ` Window ` into a ` Button ` 's ` clicked ` signal,
35+ you would create a reference cycle between the window, button, signal handler and again the window.
36+ This would lead to the whole cycle to be kept alive forever and leaked. The solution to this is to
37+ make one of the references a weak reference, in this case the reference to the window that is
38+ passed into the ` clicked ` signal handler. See also the ` Rc ` documentation about
39+ [ reference cycles] ( https://doc.rust-lang.org/std/rc/index.html ) .
40+
41+ ### Subclass
42+
43+ The "subclass" cargo feature was removed from all crates and is instead enabled by default with
44+ this release. The GObject subclassing support matured a lot over the last months and is ready for
45+ wider usage. A basic example for subclassing ` gtk::Application ` and ` gtk::ApplicationWindow ` can
46+ be found [ here] ( https://github.com/gtk-rs/examples/blob/master/src/bin/basic_subclass.rs ) , another
47+ example using custom ` glib::Object ` subclasses as part of a ` gtk::ListBox ` model can be found
48+ [ here] ( https://github.com/gtk-rs/examples/blob/master/src/bin/listbox_model.rs ) and various examples
49+ for creating GStreamer elements [ here] ( https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs ) .
50+
51+ While there are still subclassing bindings missing for many types, various basic types in the ` gio ` ,
52+ ` gtk ` and ` gstreamer ` crates are covered already. If something is missing for you, please let us
53+ know with an issue or, even better, a pull request.
54+
55+ Thanks to subclassing being a first-class citizen of the bindings, there is also an adapter
56+ available for making any ` std::io::Read ` available as ` gio::InputStream ` and any ` std::io::Write `
57+ as ` gio::OutputStream ` : ` gio::ReadInputStream ` and ` gio::WriteOutputStream ` . Adapters in the other
58+ direction are available as ` gio::InputStream::into_read() ` and ` gio::OutputStream::into_write() ` .
59+
60+ ### Futures
61+
62+ The futures support was ported to ` std ` ` Future ` s and ` futures ` 0.3, and as ` async/await ` is
63+ stabilized now it was also enabled by default. The "futures" feature is not needed anymore.
64+
65+ With the futures support in ` gio ` and other modules it is now possible to write applications making
66+ use of asynchronous I/O with ` async/await ` , which allows writing asynchronous code in a much simpler
67+ way that looks close to the equivalent synchronous code. Check
68+ [ async/await stable] ( https://blog.rust-lang.org/2019/11/07/Async-await-stable.html ) on the official
69+ Rust blog for more details.
70+
71+ An example making use of this with ` gio ` 's asynchronous file reading support can be found
72+ [ here] ( https://github.com/gtk-rs/examples/blob/master/src/bin/gio_futures_await.rs ) . While it is
73+ not as streamlined as with native Rust crates like [ async-std] ( https://async.rs ) or
74+ [ tokio] ( https://tokio.rs ) because of how the ` gio ` API works, it nonetheless much more convenient
75+ to work with than the previous (but still available) callback-based approach.
76+
77+ Another example that shows integration of ` gio ` with generic Rust futures crates can be found
78+ [ here] ( https://github.com/gtk-rs/examples/blob/pending/src/bin/gio_async_tls.rs ) . Each
79+ ` gio::PollableInputStream ` and ` gio::PollableOutputStream ` can be converted into an ` AsyncRead ` /
80+ ` AsyncWrite ` , and by this allows integration with the wider Rust async ecosystem. In this case a
81+ ` gio ` TCP connection is wrapped in a TLS connection provided by the ` async-tls ` crate, which uses
82+ ` rustls ` as underlying TLS implementation.
83+
84+ ### GTK4
85+
86+ We have initial GTK4 bindings now, which are the result of [ @sfanxiang ] [ @sfanxiang ] 's
87+ GSoC project this year. While not part of this release because GTK4 itself is still not API stable,
88+ you can also try it from git. The GTK4 bindings can be found [ here] ( https://github.com/gtk-rs/gtk4 ) .
89+ Once there are release candidates of GTK4 we will also do alpha releases of the bindings.
90+
91+ ### Cairo improvements
92+
93+ The ` cairo ` bindings now consistently return ` Result ` s for various functions instead of sometimes
94+ ` Option ` s, sometimes silently failing. Many ` cairo ` operations return an actual ` Surface ` in an
95+ error state if something goes wrong, and this surface will then (usually silently) fail any future
96+ operations on it. Instead of returning the surface, an ` Err ` is returned now as it should.
97+
98+ ### GTK Builder improvements
99+
100+ In ` gtk::Builder ` UI description files it is possible to declare signal handlers for the widgets.
101+ While it's not possible to connect them automatically to functions in Rust in a safe way, it is now
102+ possible for applications to implement the connection logic themselves based on the information from
103+ the UI description. ` gtk::Builder::connect_signals_full() ` allows to provide closures for each
104+ signal handler name that is given in the UI description.
105+
106+ ### ` glib::Value::get ` improvements
107+
108+ ` glib::Value::get() ` was changed to allow distinguishing between the value containing a ` None ` and
109+ trying to get a value of the wrong type out of it. This means that it now returns a ` Result ` , and
110+ also that for types that can't possibly be ` None ` (e.g. integer types), ` Value::get_some() ` is
111+ provided as a helper to not require unwrapping the returned ` Option ` from the normal ` Value::get() ` .
112+
113+ That's it for biggest changes. A lot of other small ones are in as well. So enjoy!
10114
11115### Changes
12116
@@ -16,29 +120,23 @@ For the interested ones, here is the list of the merged pull requests:
16120
17121 * [ Update with eoan's gir-files] ( https://github.com/gtk-rs/sys/pull/138 )
18122 * [ Add gtk4 files] ( https://github.com/gtk-rs/sys/pull/145 )
19- * [ Regen] ( https://github.com/gtk-rs/sys/pull/148 )
20123 * [ Remove graphene] ( https://github.com/gtk-rs/sys/pull/149 )
21- * [ Regen] ( https://github.com/gtk-rs/sys/pull/150 )
22- * [ Regen] ( https://github.com/gtk-rs/sys/pull/152 )
23124 * [ Update minimum rust version to 1.39] ( https://github.com/gtk-rs/sys/pull/155 )
24125 * [ Use tempfile in tests] ( https://github.com/gtk-rs/sys/pull/154 )
25126
26127[ glib] ( https://github.com/gtk-rs/glib ) :
27128
28129 * [ New version] ( https://github.com/gtk-rs/glib/pull/502 )
29- * [ Regen] ( https://github.com/gtk-rs/glib/pull/504 )
30130 * [ Zeroed] ( https://github.com/gtk-rs/glib/pull/505 )
31131 * [ Fix handling of GValues containing a floating GObject] ( https://github.com/gtk-rs/glib/pull/506 )
32- * [ Publish new 0 8] ( https://github.com/gtk-rs/glib/pull/507 )
33132 * [ Implement FromGlib and ToGlib traits on Pid type] ( https://github.com/gtk-rs/glib/pull/508 )
34133 * [ Mark ByteArray::set_size() as unsafe] ( https://github.com/gtk-rs/glib/pull/512 )
35- * [ Value::get: return a Result to account for type mismatch...] ( https://github.com/gtk-rs/glib/pull/513 )
134+ * [ Value::get: return a Result to account for type mismatch...] ( https://github.com/gtk-rs/glib/pull/513 )
36135 * [ Remove tests which panic in signals] ( https://github.com/gtk-rs/glib/pull/519 )
37136 * [ value::GetError: add a constructor and make fields public] ( https://github.com/gtk-rs/glib/pull/517 )
38137 * [ Improve docs.rs documentation] ( https://github.com/gtk-rs/glib/pull/511 )
39138 * [ Remove subclass feature] ( https://github.com/gtk-rs/glib/pull/521 )
40139 * [ Fully qualify inner macros for exported macros...] ( https://github.com/gtk-rs/glib/pull/522 )
41- * [ Publish new 0.8] ( https://github.com/gtk-rs/glib/pull/523 )
42140 * [ Fix invalid cargo key for docs.rs] ( https://github.com/gtk-rs/glib/pull/524 )
43141 * [ Implement Value::transform()] ( https://github.com/gtk-rs/glib/pull/525 )
44142 * [ remove not needed anymore libffi fix] ( https://github.com/gtk-rs/glib/pull/528 )
@@ -55,8 +153,6 @@ For the interested ones, here is the list of the merged pull requests:
55153 * [ KeyFile::get_string() can return a string in error case that still ha…] ( https://github.com/gtk-rs/glib/pull/544 )
56154 * [ Remove glib_floating_reference_guard!() macro] ( https://github.com/gtk-rs/glib/pull/548 )
57155 * [ Manually implement FFI code for GObject instead of using glib_shared_wrapper!] ( https://github.com/gtk-rs/glib/pull/547 )
58- * [ Regen] ( https://github.com/gtk-rs/glib/pull/549 )
59- * [ Regen] ( https://github.com/gtk-rs/glib/pull/550 )
60156
61157[ cairo] ( https://github.com/gtk-rs/cairo ) :
62158
@@ -77,40 +173,31 @@ For the interested ones, here is the list of the merged pull requests:
77173
78174[ sourceview] ( https://github.com/gtk-rs/sourceview ) :
79175
80- * [ Regen] ( https://github.com/gtk-rs/sourceview/pull/103 )
81176 * [ Fix boxing in async func] ( https://github.com/gtk-rs/sourceview/pull/107 )
82177 * [ Improve docs.rs documentation] ( https://github.com/gtk-rs/sourceview/pull/105 )
83178 * [ better handling of dox feature] ( https://github.com/gtk-rs/sourceview/pull/108 )
84179 * [ Use IsA for property setters] ( https://github.com/gtk-rs/sourceview/pull/110 )
85180 * [ Generate builders] ( https://github.com/gtk-rs/sourceview/pull/111 )
86181 * [ Builder use implemented interfaces properties] ( https://github.com/gtk-rs/sourceview/pull/112 )
87182 * [ Fix invalid cargo key for docs.rs] ( https://github.com/gtk-rs/sourceview/pull/113 )
88- * [ Regen] ( https://github.com/gtk-rs/sourceview/pull/114 )
89183 * [ Use tempfile in tests] ( https://github.com/gtk-rs/sourceview/pull/115 )
90184 * [ Derive Default, Clone for builders] ( https://github.com/gtk-rs/sourceview/pull/116 )
91185 * [ Regen] ( https://github.com/gtk-rs/sourceview/pull/117 )
92186
93187[ atk] ( https://github.com/gtk-rs/atk ) :
94188
95- * [ New version] ( https://github.com/gtk-rs/atk/pull/33 )
96- * [ Regen] ( https://github.com/gtk-rs/atk/pull/34 )
97189 * [ Improve docs.rs documentation] ( https://github.com/gtk-rs/atk/pull/35 )
98190 * [ Update for new ` Value::get ` signature] ( https://github.com/gtk-rs/atk/pull/36 )
99191 * [ better handling of docs.rs features] ( https://github.com/gtk-rs/atk/pull/37 )
100192 * [ Use IsA for property setters] ( https://github.com/gtk-rs/atk/pull/38 )
101193 * [ Fix invalid cargo key for docs.rs] ( https://github.com/gtk-rs/atk/pull/39 )
102194 * [ remove not needed anymore libffi fix] ( https://github.com/gtk-rs/atk/pull/40 )
103- * [ Regen] ( https://github.com/gtk-rs/atk/pull/41 )
104- * [ Regen] ( https://github.com/gtk-rs/atk/pull/43 )
105195 * [ Update minimum required rust version] ( https://github.com/gtk-rs/atk/pull/44 )
106- * [ Regen] ( https://github.com/gtk-rs/atk/pull/45 )
107196
108197[ gio] ( https://github.com/gtk-rs/gio ) :
109198
110199 * [ Fix docs for manual functions \[ ci skip\] ] ( https://github.com/gtk-rs/gio/pull/224 )
111- * [ Regen] ( https://github.com/gtk-rs/gio/pull/225 )
112200 * [ New version] ( https://github.com/gtk-rs/gio/pull/227 )
113- * [ Regen] ( https://github.com/gtk-rs/gio/pull/228 )
114201 * [ Generate FileEnumerator] ( https://github.com/gtk-rs/gio/pull/229 )
115202 * [ Improve docs.rs documentation] ( https://github.com/gtk-rs/gio/pull/231 )
116203 * [ Update for new ` Value::get ` signature] ( https://github.com/gtk-rs/gio/pull/233 )
@@ -137,38 +224,29 @@ For the interested ones, here is the list of the merged pull requests:
137224 * [ Derive Default, Clone for builders] ( https://github.com/gtk-rs/gio/pull/259 )
138225 * [ Remove usage of glib_floating_reference_guard!()] ( https://github.com/gtk-rs/gio/pull/260 )
139226 * [ Fix some clippy warnings by removing unused lifetime parameters] ( https://github.com/gtk-rs/gio/pull/261 )
140- * [ Regen] ( https://github.com/gtk-rs/gio/pull/262 )
141227
142228[ pango] ( https://github.com/gtk-rs/pango ) :
143229
144- * [ regen] ( https://github.com/gtk-rs/pango/pull/155 )
145230 * [ Improve docs.rs documentation] ( https://github.com/gtk-rs/pango/pull/157 )
146231 * [ (#156 ): Manual implementations of PangoGravity functions] ( https://github.com/gtk-rs/pango/pull/158 )
147232 * [ Improve docs.rs handling] ( https://github.com/gtk-rs/pango/pull/159 )
148233 * [ Fix invalid cargo key for docs.rs] ( https://github.com/gtk-rs/pango/pull/162 )
149234 * [ Add pango-glyph interfaces ] ( https://github.com/gtk-rs/pango/pull/163 )
150235 * [ remove not needed anymore libffi fix] ( https://github.com/gtk-rs/pango/pull/164 )
151236 * [ Add PangoAttrSize] ( https://github.com/gtk-rs/pango/pull/166 )
152- * [ Regen] ( https://github.com/gtk-rs/pango/pull/169 )
153- * [ Regen] ( https://github.com/gtk-rs/pango/pull/171 )
154237
155238[ gdk-pixbuf] ( https://github.com/gtk-rs/gdk-pixbuf ) :
156239
157- * [ Regen] ( https://github.com/gtk-rs/gdk-pixbuf/pull/127 )
158240 * [ Update for new ` Value::get ` signature] ( https://github.com/gtk-rs/gdk-pixbuf/pull/128 )
159241 * [ Improve docs.rs documentation] ( https://github.com/gtk-rs/gdk-pixbuf/pull/129 )
160242 * [ Improve docs.rs handling] ( https://github.com/gtk-rs/gdk-pixbuf/pull/130 )
161243 * [ Fix invalid cargo key for docs.rs] ( https://github.com/gtk-rs/gdk-pixbuf/pull/131 )
162244 * [ remove not needed anymore libffi fix] ( https://github.com/gtk-rs/gdk-pixbuf/pull/132 )
163- * [ Regen] ( https://github.com/gtk-rs/gdk-pixbuf/pull/133 )
164- * [ Regenerate with latest gir] ( https://github.com/gtk-rs/gdk-pixbuf/pull/134 )
165- * [ Regen] ( https://github.com/gtk-rs/gdk-pixbuf/pull/135 )
166245
167246[ gdk] ( https://github.com/gtk-rs/gdk ) :
168247
169248 * [ Fix docs for manual functions \[ ci skip\] ] ( https://github.com/gtk-rs/gdk/pull/299 )
170249 * [ Fix build after #299 ] ( https://github.com/gtk-rs/gdk/pull/302 )
171- * [ Regen] ( https://github.com/gtk-rs/gdk/pull/303 )
172250 * [ Improve docs.rs documentation] ( https://github.com/gtk-rs/gdk/pull/305 )
173251 * [ Update for new ` Value::get ` signature] ( https://github.com/gtk-rs/gdk/pull/307 )
174252 * [ Cairo interactions: auto load Pixbuf & Surface Exts] ( https://github.com/gtk-rs/gdk/pull/309 )
@@ -180,17 +258,13 @@ For the interested ones, here is the list of the merged pull requests:
180258 * [ Fix invalid cargo key for docs.rs] ( https://github.com/gtk-rs/gdk/pull/316 )
181259 * [ remove not needed anymore libffi fix] ( https://github.com/gtk-rs/gdk/pull/317 )
182260 * [ Generate Keymap bindings] ( https://github.com/gtk-rs/gdk/pull/311 )
183- * [ Regen] ( https://github.com/gtk-rs/gdk/pull/318 )
184261 * [ Don't reexport prelude content] ( https://github.com/gtk-rs/gdk/pull/319 )
185- * [ Regen] ( https://github.com/gtk-rs/gdk/pull/320 )
186262
187263[ gtk] ( https://github.com/gtk-rs/gtk ) :
188264
189265 * [ Fix docs for manual functions \[ ci skip\] ] ( https://github.com/gtk-rs/gtk/pull/832 )
190266 * [ PadController is disguised so trait don't needed] ( https://github.com/gtk-rs/gtk/pull/839 )
191267 * [ Make PadController::set_action_entries() public so it can actually be…] ( https://github.com/gtk-rs/gtk/pull/841 )
192- * [ New version] ( https://github.com/gtk-rs/gtk/pull/845 )
193- * [ Regen] ( https://github.com/gtk-rs/gtk/pull/849 )
194268 * [ Implement Builder::connect_signals_full] ( https://github.com/gtk-rs/gtk/pull/852 )
195269 * [ Generate GtkWindowExt::set_geometry_hints] ( https://github.com/gtk-rs/gtk/pull/857 )
196270 * [ subclass: Get started on subclassing GtkWidget] ( https://github.com/gtk-rs/gtk/pull/861 )
@@ -220,29 +294,26 @@ For the interested ones, here is the list of the merged pull requests:
220294 * [ Fix format issue] ( https://github.com/gtk-rs/gtk/pull/903 )
221295 * [ remove not needed anymore libffi fix] ( https://github.com/gtk-rs/gtk/pull/904 )
222296 * [ subclass: Always allow to override the vfuns of classes] ( https://github.com/gtk-rs/gtk/pull/908 )
223- * [ Regen] ( https://github.com/gtk-rs/gtk/pull/910 )
224297 * [ Fix various imports to fix the build] ( https://github.com/gtk-rs/gtk/pull/911 )
225298 * [ Make AccelGroup::connect() and ::connect_by_path() more usable] ( https://github.com/gtk-rs/gtk/pull/915 )
226299 * [ Add renaming for WidgetExt::set_name and BuildableExt::set_name] ( https://github.com/gtk-rs/gtk/pull/917 )
227- * [ Regenerate with latest gir] ( https://github.com/gtk-rs/gtk/pull/918 )
228300 * [ Derive Default for builders] ( https://github.com/gtk-rs/gtk/pull/919 )
229301 * [ subclass/container: widget in set_focu_child should be Nullable] ( https://github.com/gtk-rs/gtk/pull/922 )
230302 * [ subclass/widget: Implement default handling for parent events] ( https://github.com/gtk-rs/gtk/pull/921 )
231- * [ Regen] ( https://github.com/gtk-rs/gtk/pull/923 )
232303
233304[ pangocairo] ( https://github.com/gtk-rs/pangocairo ) :
234305
235306 * [ Fix docs for manual functions \[ ci skip\] ] ( https://github.com/gtk-rs/pangocairo/pull/53 )
236307 * [ Improve docs.rs documentation] ( https://github.com/gtk-rs/pangocairo/pull/54 )
237308 * [ Fix invalid cargo key for docs.rs] ( https://github.com/gtk-rs/pangocairo/pull/55 )
238309 * [ remove not needed anymore libffi fix] ( https://github.com/gtk-rs/pangocairo/pull/57 )
239- * [ Regen] ( https://github.com/gtk-rs/pangocairo/pull/58 )
240310 * [ Fix build and reexports] ( https://github.com/gtk-rs/pangocairo/pull/59 )
241- * [ Regen] ( https://github.com/gtk-rs/pangocairo/pull/61 )
242311 * [ Make FontMap::set_default() a static function and allow passing None …] ( https://github.com/gtk-rs/pangocairo/pull/62 )
243312
244313[ gtk-test] ( https://github.com/gtk-rs/gtk-test ) :
245314
315+ * [ Update to last versions] ( https://github.com/gtk-rs/gtk-test/pull/32 )
316+
246317
247318All this was possible thanks to the [ gtk-rs/gir] ( https://github.com/gtk-rs/gir ) project as well:
248319
@@ -272,7 +343,7 @@ All this was possible thanks to the [gtk-rs/gir](https://github.com/gtk-rs/gir)
272343 * [ Add generic parameters to builder methods] ( https://github.com/gtk-rs/gir/pull/853 )
273344 * [ Fix invalid import add] ( https://github.com/gtk-rs/gir/pull/858 )
274345 * [ Remove dependencies] ( https://github.com/gtk-rs/gir/pull/855 )
275- * [ Extend gpointer to void* ] ( https://github.com/gtk-rs/gir/pull/860 )
346+ * [ Extend gpointer to void\ *] ( https://github.com/gtk-rs/gir/pull/860 )
276347 * [ Fix missing parenthesis on return types] ( https://github.com/gtk-rs/gir/pull/861 )
277348 * [ Add missing from_glib conversion for Pid] ( https://github.com/gtk-rs/gir/pull/864 )
278349 * [ Correctly generate glib::Error import] ( https://github.com/gtk-rs/gir/pull/863 )
@@ -304,7 +375,9 @@ Thanks to all of our contributors for their (awesome!) work on this release:
304375 * [ @nipunn1313 ] ( https://github.com/nipunn1313 )
305376 * [ @RazrFalcon ] ( https://github.com/RazrFalcon )
306377 * [ @sdroege ] ( https://github.com/sdroege )
307- * [ @sfanxiang ] ( https://github.com/ sfanxiang)
378+ * [ @sfanxiang ] [ @ sfanxiang]
308379 * [ @silwol ] ( https://github.com/silwol )
309380 * [ @timbodeit ] ( https://github.com/timbodeit )
310381 * [ @velyan ] ( https://github.com/velyan )
382+
383+ [ @sfanxiang ] : https://github.com/sfanxiang
0 commit comments