1
1
---
2
2
layout : post
3
3
author : GuillaumeGomez
4
- title : Simplification and more everything
4
+ title : Simplification and more of everything
5
5
categories : [front, crates]
6
- date : 2019-12-14 16 :00:00 +0000
6
+ date : 2019-12-15 19 :00:00 +0000
7
7
---
8
8
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!
10
114
11
115
### Changes
12
116
@@ -16,29 +120,23 @@ For the interested ones, here is the list of the merged pull requests:
16
120
17
121
* [ Update with eoan's gir-files] ( https://github.com/gtk-rs/sys/pull/138 )
18
122
* [ Add gtk4 files] ( https://github.com/gtk-rs/sys/pull/145 )
19
- * [ Regen] ( https://github.com/gtk-rs/sys/pull/148 )
20
123
* [ 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 )
23
124
* [ Update minimum rust version to 1.39] ( https://github.com/gtk-rs/sys/pull/155 )
24
125
* [ Use tempfile in tests] ( https://github.com/gtk-rs/sys/pull/154 )
25
126
26
127
[ glib] ( https://github.com/gtk-rs/glib ) :
27
128
28
129
* [ New version] ( https://github.com/gtk-rs/glib/pull/502 )
29
- * [ Regen] ( https://github.com/gtk-rs/glib/pull/504 )
30
130
* [ Zeroed] ( https://github.com/gtk-rs/glib/pull/505 )
31
131
* [ 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 )
33
132
* [ Implement FromGlib and ToGlib traits on Pid type] ( https://github.com/gtk-rs/glib/pull/508 )
34
133
* [ 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 )
36
135
* [ Remove tests which panic in signals] ( https://github.com/gtk-rs/glib/pull/519 )
37
136
* [ value::GetError: add a constructor and make fields public] ( https://github.com/gtk-rs/glib/pull/517 )
38
137
* [ Improve docs.rs documentation] ( https://github.com/gtk-rs/glib/pull/511 )
39
138
* [ Remove subclass feature] ( https://github.com/gtk-rs/glib/pull/521 )
40
139
* [ 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 )
42
140
* [ Fix invalid cargo key for docs.rs] ( https://github.com/gtk-rs/glib/pull/524 )
43
141
* [ Implement Value::transform()] ( https://github.com/gtk-rs/glib/pull/525 )
44
142
* [ 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:
55
153
* [ KeyFile::get_string() can return a string in error case that still ha…] ( https://github.com/gtk-rs/glib/pull/544 )
56
154
* [ Remove glib_floating_reference_guard!() macro] ( https://github.com/gtk-rs/glib/pull/548 )
57
155
* [ 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 )
60
156
61
157
[ cairo] ( https://github.com/gtk-rs/cairo ) :
62
158
@@ -77,40 +173,31 @@ For the interested ones, here is the list of the merged pull requests:
77
173
78
174
[ sourceview] ( https://github.com/gtk-rs/sourceview ) :
79
175
80
- * [ Regen] ( https://github.com/gtk-rs/sourceview/pull/103 )
81
176
* [ Fix boxing in async func] ( https://github.com/gtk-rs/sourceview/pull/107 )
82
177
* [ Improve docs.rs documentation] ( https://github.com/gtk-rs/sourceview/pull/105 )
83
178
* [ better handling of dox feature] ( https://github.com/gtk-rs/sourceview/pull/108 )
84
179
* [ Use IsA for property setters] ( https://github.com/gtk-rs/sourceview/pull/110 )
85
180
* [ Generate builders] ( https://github.com/gtk-rs/sourceview/pull/111 )
86
181
* [ Builder use implemented interfaces properties] ( https://github.com/gtk-rs/sourceview/pull/112 )
87
182
* [ 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 )
89
183
* [ Use tempfile in tests] ( https://github.com/gtk-rs/sourceview/pull/115 )
90
184
* [ Derive Default, Clone for builders] ( https://github.com/gtk-rs/sourceview/pull/116 )
91
185
* [ Regen] ( https://github.com/gtk-rs/sourceview/pull/117 )
92
186
93
187
[ atk] ( https://github.com/gtk-rs/atk ) :
94
188
95
- * [ New version] ( https://github.com/gtk-rs/atk/pull/33 )
96
- * [ Regen] ( https://github.com/gtk-rs/atk/pull/34 )
97
189
* [ Improve docs.rs documentation] ( https://github.com/gtk-rs/atk/pull/35 )
98
190
* [ Update for new ` Value::get ` signature] ( https://github.com/gtk-rs/atk/pull/36 )
99
191
* [ better handling of docs.rs features] ( https://github.com/gtk-rs/atk/pull/37 )
100
192
* [ Use IsA for property setters] ( https://github.com/gtk-rs/atk/pull/38 )
101
193
* [ Fix invalid cargo key for docs.rs] ( https://github.com/gtk-rs/atk/pull/39 )
102
194
* [ 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 )
105
195
* [ Update minimum required rust version] ( https://github.com/gtk-rs/atk/pull/44 )
106
- * [ Regen] ( https://github.com/gtk-rs/atk/pull/45 )
107
196
108
197
[ gio] ( https://github.com/gtk-rs/gio ) :
109
198
110
199
* [ 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 )
112
200
* [ New version] ( https://github.com/gtk-rs/gio/pull/227 )
113
- * [ Regen] ( https://github.com/gtk-rs/gio/pull/228 )
114
201
* [ Generate FileEnumerator] ( https://github.com/gtk-rs/gio/pull/229 )
115
202
* [ Improve docs.rs documentation] ( https://github.com/gtk-rs/gio/pull/231 )
116
203
* [ 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:
137
224
* [ Derive Default, Clone for builders] ( https://github.com/gtk-rs/gio/pull/259 )
138
225
* [ Remove usage of glib_floating_reference_guard!()] ( https://github.com/gtk-rs/gio/pull/260 )
139
226
* [ 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 )
141
227
142
228
[ pango] ( https://github.com/gtk-rs/pango ) :
143
229
144
- * [ regen] ( https://github.com/gtk-rs/pango/pull/155 )
145
230
* [ Improve docs.rs documentation] ( https://github.com/gtk-rs/pango/pull/157 )
146
231
* [ (#156 ): Manual implementations of PangoGravity functions] ( https://github.com/gtk-rs/pango/pull/158 )
147
232
* [ Improve docs.rs handling] ( https://github.com/gtk-rs/pango/pull/159 )
148
233
* [ Fix invalid cargo key for docs.rs] ( https://github.com/gtk-rs/pango/pull/162 )
149
234
* [ Add pango-glyph interfaces ] ( https://github.com/gtk-rs/pango/pull/163 )
150
235
* [ remove not needed anymore libffi fix] ( https://github.com/gtk-rs/pango/pull/164 )
151
236
* [ 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 )
154
237
155
238
[ gdk-pixbuf] ( https://github.com/gtk-rs/gdk-pixbuf ) :
156
239
157
- * [ Regen] ( https://github.com/gtk-rs/gdk-pixbuf/pull/127 )
158
240
* [ Update for new ` Value::get ` signature] ( https://github.com/gtk-rs/gdk-pixbuf/pull/128 )
159
241
* [ Improve docs.rs documentation] ( https://github.com/gtk-rs/gdk-pixbuf/pull/129 )
160
242
* [ Improve docs.rs handling] ( https://github.com/gtk-rs/gdk-pixbuf/pull/130 )
161
243
* [ Fix invalid cargo key for docs.rs] ( https://github.com/gtk-rs/gdk-pixbuf/pull/131 )
162
244
* [ 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 )
166
245
167
246
[ gdk] ( https://github.com/gtk-rs/gdk ) :
168
247
169
248
* [ Fix docs for manual functions \[ ci skip\] ] ( https://github.com/gtk-rs/gdk/pull/299 )
170
249
* [ Fix build after #299 ] ( https://github.com/gtk-rs/gdk/pull/302 )
171
- * [ Regen] ( https://github.com/gtk-rs/gdk/pull/303 )
172
250
* [ Improve docs.rs documentation] ( https://github.com/gtk-rs/gdk/pull/305 )
173
251
* [ Update for new ` Value::get ` signature] ( https://github.com/gtk-rs/gdk/pull/307 )
174
252
* [ 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:
180
258
* [ Fix invalid cargo key for docs.rs] ( https://github.com/gtk-rs/gdk/pull/316 )
181
259
* [ remove not needed anymore libffi fix] ( https://github.com/gtk-rs/gdk/pull/317 )
182
260
* [ Generate Keymap bindings] ( https://github.com/gtk-rs/gdk/pull/311 )
183
- * [ Regen] ( https://github.com/gtk-rs/gdk/pull/318 )
184
261
* [ Don't reexport prelude content] ( https://github.com/gtk-rs/gdk/pull/319 )
185
- * [ Regen] ( https://github.com/gtk-rs/gdk/pull/320 )
186
262
187
263
[ gtk] ( https://github.com/gtk-rs/gtk ) :
188
264
189
265
* [ Fix docs for manual functions \[ ci skip\] ] ( https://github.com/gtk-rs/gtk/pull/832 )
190
266
* [ PadController is disguised so trait don't needed] ( https://github.com/gtk-rs/gtk/pull/839 )
191
267
* [ 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 )
194
268
* [ Implement Builder::connect_signals_full] ( https://github.com/gtk-rs/gtk/pull/852 )
195
269
* [ Generate GtkWindowExt::set_geometry_hints] ( https://github.com/gtk-rs/gtk/pull/857 )
196
270
* [ 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:
220
294
* [ Fix format issue] ( https://github.com/gtk-rs/gtk/pull/903 )
221
295
* [ remove not needed anymore libffi fix] ( https://github.com/gtk-rs/gtk/pull/904 )
222
296
* [ 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 )
224
297
* [ Fix various imports to fix the build] ( https://github.com/gtk-rs/gtk/pull/911 )
225
298
* [ Make AccelGroup::connect() and ::connect_by_path() more usable] ( https://github.com/gtk-rs/gtk/pull/915 )
226
299
* [ 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 )
228
300
* [ Derive Default for builders] ( https://github.com/gtk-rs/gtk/pull/919 )
229
301
* [ subclass/container: widget in set_focu_child should be Nullable] ( https://github.com/gtk-rs/gtk/pull/922 )
230
302
* [ 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 )
232
303
233
304
[ pangocairo] ( https://github.com/gtk-rs/pangocairo ) :
234
305
235
306
* [ Fix docs for manual functions \[ ci skip\] ] ( https://github.com/gtk-rs/pangocairo/pull/53 )
236
307
* [ Improve docs.rs documentation] ( https://github.com/gtk-rs/pangocairo/pull/54 )
237
308
* [ Fix invalid cargo key for docs.rs] ( https://github.com/gtk-rs/pangocairo/pull/55 )
238
309
* [ remove not needed anymore libffi fix] ( https://github.com/gtk-rs/pangocairo/pull/57 )
239
- * [ Regen] ( https://github.com/gtk-rs/pangocairo/pull/58 )
240
310
* [ Fix build and reexports] ( https://github.com/gtk-rs/pangocairo/pull/59 )
241
- * [ Regen] ( https://github.com/gtk-rs/pangocairo/pull/61 )
242
311
* [ Make FontMap::set_default() a static function and allow passing None …] ( https://github.com/gtk-rs/pangocairo/pull/62 )
243
312
244
313
[ gtk-test] ( https://github.com/gtk-rs/gtk-test ) :
245
314
315
+ * [ Update to last versions] ( https://github.com/gtk-rs/gtk-test/pull/32 )
316
+
246
317
247
318
All this was possible thanks to the [ gtk-rs/gir] ( https://github.com/gtk-rs/gir ) project as well:
248
319
@@ -272,7 +343,7 @@ All this was possible thanks to the [gtk-rs/gir](https://github.com/gtk-rs/gir)
272
343
* [ Add generic parameters to builder methods] ( https://github.com/gtk-rs/gir/pull/853 )
273
344
* [ Fix invalid import add] ( https://github.com/gtk-rs/gir/pull/858 )
274
345
* [ 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 )
276
347
* [ Fix missing parenthesis on return types] ( https://github.com/gtk-rs/gir/pull/861 )
277
348
* [ Add missing from_glib conversion for Pid] ( https://github.com/gtk-rs/gir/pull/864 )
278
349
* [ 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:
304
375
* [ @nipunn1313 ] ( https://github.com/nipunn1313 )
305
376
* [ @RazrFalcon ] ( https://github.com/RazrFalcon )
306
377
* [ @sdroege ] ( https://github.com/sdroege )
307
- * [ @sfanxiang ] ( https://github.com/ sfanxiang)
378
+ * [ @sfanxiang ] [ @ sfanxiang]
308
379
* [ @silwol ] ( https://github.com/silwol )
309
380
* [ @timbodeit ] ( https://github.com/timbodeit )
310
381
* [ @velyan ] ( https://github.com/velyan )
382
+
383
+ [ @sfanxiang ] : https://github.com/sfanxiang
0 commit comments