New release - more complete, safer
Welcome everyone to this whole new gtk-rs release! Time to check what was added/updated in this new version.
Change of minimum supported Rust version §
Important information: the minimal gtk-rs supported Rust version is now the 1.34
. We now use the TryFrom
trait which was stabilized in this version.
Stepping back? §
This release removes the Into
trait implementation we added previously when a nullable type was expected. let’s take an example!
Before we could do this:
let label = gtk::Label::new("Hello");
let another_label = gtk::Label::new(None);
Now we have to wrap our "Hello"
into Some()
:
let label = gtk::Label::new(Some("Hello"));
let another_label = gtk::Label::new(None);
There are two reasons behind going back on this feature:
The first one is about the Rust compiler error messages. In some cases, you were forced to provide generics because it couldn’t infer them itself and then led to annoying situations where you had to try to figure out what was going on.
The second one is to go back to some Rust fundamentals: being explicit. Reading code where some obscure transformations occur internally to the API is clearly slowing down the code comprehension process. For example, when the API was expecting a generic type:
let label = gtk::Label::new("Hello");
// We remove the associated widget with mnemonic:
label.set_mnemonic_widget(None);
If you try this code, you’ll see the compiler complaining about the fact that it cannot determine what is the generic type None
. If you want to fix this code, you had to do:
label.set_mnemonic_widget(None::<gtk::Widget>);
Which isn’t very nice…
We talked about this change for a while and decided it was the best for our users from our point of view.
cairo changes §
We made some changes into cairo
type hierarchies that led to a global improvement. To sum it up very shortly (thanks to @SimonSapin for providing it!):
- Patterns: pseudo-inheritance with Deref (like surfaces already do) instead of an enum of each pattern type.
- PDF/PS/SVG: a single surface type each instead of a public module, and restrict streams to
'static
to make them sound. - XBC: a struct like other surface types, instead of a trait.
- Inherent methods instead of various extension traits
If you want the complete description, it is available in its linked issue.
Builders §
Another big add to this release was the generation of builders for widgets. Builders allow to set construct-only properties and other construct properties when creating the widget. For example:
let button = gtk::LockButtonBuilder::new()
.text_lock("Lock")
.text_unlock("Unlock")
.build();
Futures §
We now use the std::futures
, which means that we can do now do async/await. A full example is available here.
Other things? §
Actually yes! But as you can guess, it’d be too just too long to describe them all. Let’s go through them quickly:
- New types/functions were generated (
gio
is certainly the crate which benefited the most from it). - Some methods which weren’t supposed to be “inherited” aren’t anymore.
- Automatically generated source code is now clearer: the trampoline functions (used for signals for examples) are now inside the function which used them.
- Crates source code has received some
rustfmt
run. - Lot of fixes and small improvements…
Changes §
For the interested ones, here is the list of the merged pull requests:
sys:
glib:
- Move trampolines
- Implement futures-0.3
Spawn
for&MainContext
- Add init/clear function for boxed types
- Manually implement Clone for Sender/SyncSender
- Fix dyn and import warnings
- subclass: panic with error message when registering existing type
- Generate SpawnFlags
- Add missing traits
- Add ByteArray binding
- Always ref-sink after g_object_new() if the type inherits from GIniti…
- Run futures code and tests when building with nightly
- Port to futures 0.3
- add doc rule
- gbytes: Impl AsRef<[u8]>
- Remove xx_sys to xx_ffi renaming
- Add missing #[doc(hidden)]
- Fix some clippy warnings
- Small release
- Filename from uri fix
- Don’t use deprecated ATOMIC_USIZE_INIT
- gstring: Implement Hash trait
- For setting properties and the return value of signal handlers relax …
- Rework type hierarchies
- Add a safe API for user data
- Export SurfaceExt from the private surface module
- Fix warning
- Move trampolines
- Remove traits for disguised types without children
- Add missing feature v3_14
- Port to futures 0.3
- Remove xx_sys to xx_ffi renaming
- Remove versions from git dependencies
- Add missing version for gtk-rs-lgpl-docs
- Add dist xenial and libmount-dev dependency
atk:
gio:
- Two Option-related fixes
- Move trampolines
- Fix dyn warnings
- Generate new types
- Add new type
- Remove traits for disguised types without children
- Fix generating docs for UnixXXXStream
- Add Gir config for Unix{Input,Output}Stream
- Add support for subclassing gio::Application
- Port to futures 0.3
- add doc rule
- Remove xx_sys to xx_ffi renaming
- inet_address: add new_from_bytes constructor
- Fix failing test compilation
- Remove traits for disguised types without children
- Fix pango_language_get_sample_string SIGSEGV
- Drop v1_36_7 feature
- add doc rule
- Remove xx_sys to xx_ffi renaming
- Remove git dependency
- Move trampolines
- Remove dyn warnings
- Remove traits for disguised types without children
- Port to futures 0.3
- add doc rule
- Remove xx_sys to xx_ffi renaming
gdk:
- Update to last cairo version
- Move trampolines
- Remove traits for disguised types without children
- Remove traits for disguised types without children (the comeback!)
- Fix nullable trampolines
- add doc rule
- Fields have been generated so we can uncommented those methods
- Remove xx_sys to xx_ffi renaming
gtk:
- pad_action_entry: Fix dangling pointer
- Generate init/clear functions for TreeIter, TextIter and Border
- Move trampolines
- Remove dyn warnings
- Remove pre-init assertion to check for non-debug GTK builds
- Get entry
- Remove unneeded mutability for pango::TabArray
- Remove traits for disguised types without children
- Allow for GtkApplication to be subclasses
- Remove manually implemented Gtk.Socket
- Port to futures 0.3
- remove osx image
- Fix version for property FontChooser.level
- try to fix osx build
- Remove deprecated objects
- add doc rule
- Remove xx_sys to xx_ffi renaming
- builder: Move trait methods to traits
- Overwrite return type
- Add a special type for add_tick_callback’s return value
- Improve Dialog API
- Use final types pango::Context, pango::Layout without IsA
- add doc rule
- Remove xx_sys to xx_ffi renaming
All this was possible thanks to the gtk-rs/gir project as well:
- Add warning to gobject-sys’s build script
- Add configuration for init/clear function expressions of boxed types
- Generate trampolines directly inside functions
- Fix missing callback parameter handling
- Fix trait object warning for futures
- Don’t panic on ignored parameter in callback
- Fix gconstpointer fixup
- Use complete pointer type for trampoline return
- Use Option<&T> instead of &Option<T> for signal callback parameters
- Don’t bring trait ObjectType into scope
- Fix imports handling
- Builder setters accept references
- Add link to gir tutorial
- Improve gir errors a bit
- Ignore the <attribute> element in any other XML element
- Dont generate builders constraint and minor fixes
- Fix builders
- Use disguised in final types check
- Generate builder for widgets
- Rust 2018 and code formatting
- Fix callbacks
- More source position & rustfmt.toml
- Update sys cargo generation
- Port to futures 0.3
- Remove unneeded “mut”
- Force replacing ‘-‘ in crate name for
use
- library_postprocessing: Don’t expect c:type for FixedArray
- parser: ignore source-position
- Allow nullable trampolines with scope=”call”
- Add crate name fix for webkit2xx
- Don’t generate docs for completely deprecated items
- Handle nullable parameters for callbacks as well
- Fix some clippy warnings
- [ffi] Support alignment on objects
- Don’t use “ffi” suffix for sys crates
- Recheck crate names usage
- Allow to overwrite returned type
- Fix use order
- Fix invalid crate name generation
- Remove Into trait generation
- Don’t use transmute() for signal trampoline closures
Thanks to all of our contributors for their (awesome!) work on this release: